Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: shallow clone browserPoolOptions before normalization #1665

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,13 @@ export class PlaywrightCrawler extends BrowserCrawler<{ browserPlugins: [Playwri
const {
launchContext = {},
headless,
browserPoolOptions = {} as BrowserPoolOptions<PlaywrightPlugin>,
...browserCrawlerOptions
} = options;

const browserPoolOptions = {
...options.browserPoolOptions,
} as BrowserPoolOptions;

if (launchContext.proxyUrl) {
throw new Error('PlaywrightCrawlerOptions.launchContext.proxyUrl is not allowed in PlaywrightCrawler.'
+ 'Use PlaywrightCrawlerOptions.proxyConfiguration');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,14 @@ export class PuppeteerCrawler extends BrowserCrawler<{ browserPlugins: [Puppetee
const {
launchContext = {},
headless,
browserPoolOptions = {} as BrowserPoolOptions,
proxyConfiguration,
...browserCrawlerOptions
} = options;

const browserPoolOptions = {
...options.browserPoolOptions,
} as BrowserPoolOptions;

if (launchContext.proxyUrl) {
throw new Error('PuppeteerCrawlerOptions.launchContext.proxyUrl is not allowed in PuppeteerCrawler.'
+ 'Use PuppeteerCrawlerOptions.proxyConfiguration');
Expand Down
12 changes: 12 additions & 0 deletions test/core/crawlers/playwright_crawler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,16 @@ describe('PlaywrightCrawler', () => {
await playwrightCrawler.run();
expect(options.timeout).toEqual(timeoutSecs * 1000);
});

test('shallow clones browserPoolOptions before normalization', () => {
const options = {
browserPoolOptions: {},
requestHandler: async () => {},
};

void new PlaywrightCrawler(options);
void new PlaywrightCrawler(options);

expect(Object.keys(options.browserPoolOptions).length).toBe(0);
});
});
12 changes: 12 additions & 0 deletions test/core/crawlers/puppeteer_crawler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,18 @@ describe('PuppeteerCrawler', () => {
expect(sessions.size).toBe(3); // 3 different sessions used
});

test('shallow clones browserPoolOptions before normalization', () => {
const options = {
browserPoolOptions: {},
requestHandler: async () => {},
};

void new PuppeteerCrawler(options);
void new PuppeteerCrawler(options);

expect(Object.keys(options.browserPoolOptions).length).toBe(0);
});

if (os.platform() !== 'darwin') {
test('proxy per page', async () => {
const requestListLarge = await RequestList.open({
Expand Down