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: add headless option to BrowserCrawlerOptions #1412

Merged
merged 1 commit into from
Jul 20, 2022
Merged
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
16 changes: 14 additions & 2 deletions packages/browser-crawler/src/internals/browser-crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ export interface BrowserCrawlerOptions<
* This can only be used when `useSessionPool` is set to `true`.
*/
persistCookiesPerSession?: boolean;

/**
* Whether to run browser in headless mode. Defaults to `true`.
* Can be also set via {@link Configuration}.
*/
headless?: boolean;
}

/**
Expand Down Expand Up @@ -306,7 +312,7 @@ export abstract class BrowserCrawler<
*/
browserPool: BrowserPool<InternalBrowserPoolOptions>;

launchContext?: BrowserLaunchContext<LaunchOptions, unknown>;
launchContext: BrowserLaunchContext<LaunchOptions, unknown>;

protected userProvidedRequestHandler!: BrowserCrawlerHandleRequest<Context>;
protected navigationTimeoutMillis: number;
Expand Down Expand Up @@ -340,7 +346,7 @@ export abstract class BrowserCrawler<
requestHandlerTimeoutSecs = 60,
persistCookiesPerSession,
proxyConfiguration,
launchContext,
launchContext = {},
browserPoolOptions,
preNavigationHooks = [],
postNavigationHooks = [],
Expand All @@ -352,6 +358,7 @@ export abstract class BrowserCrawler<

failedRequestHandler,
handleFailedRequestFunction,
headless,
...basicCrawlerOptions
} = options;

Expand Down Expand Up @@ -394,6 +401,11 @@ export abstract class BrowserCrawler<
this.preNavigationHooks = preNavigationHooks;
this.postNavigationHooks = postNavigationHooks;

if (headless != null) {
this.launchContext.launchOptions ??= {} as LaunchOptions;
(this.launchContext.launchOptions as Dictionary).headless = headless;
}

if (this.useSessionPool) {
this.persistCookiesPerSession = persistCookiesPerSession !== undefined ? persistCookiesPerSession : true;
} else {
Expand Down