@crawlee/browser 4.0.0-beta.80 → 4.0.0-beta.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -233,10 +233,10 @@ export declare abstract class BrowserCrawler<Page extends CommonPage = CommonPag
|
|
|
233
233
|
launchContext: BrowserLaunchContext<LaunchOptions, unknown>;
|
|
234
234
|
protected readonly ignoreShadowRoots: boolean;
|
|
235
235
|
protected readonly ignoreIframes: boolean;
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
private readonly navigationTimeoutMillis;
|
|
237
|
+
private readonly preNavigationHooks;
|
|
238
|
+
private readonly postNavigationHooks;
|
|
239
|
+
private readonly saveResponseCookies;
|
|
240
240
|
protected static optionsShape: {
|
|
241
241
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
242
242
|
navigationTimeoutSecs: import("ow").NumberPredicate & import("ow").BasePredicate<number | undefined>;
|
|
@@ -333,22 +333,22 @@ export declare abstract class BrowserCrawler<Page extends CommonPage = CommonPag
|
|
|
333
333
|
});
|
|
334
334
|
protected buildContextPipeline(): ContextPipeline<CrawlingContext, BrowserCrawlingContext<Page, Response, Dictionary>>;
|
|
335
335
|
private containsSelectors;
|
|
336
|
-
|
|
336
|
+
private isRequestBlocked;
|
|
337
337
|
private preparePage;
|
|
338
338
|
private prepareNavigation;
|
|
339
339
|
private navigate;
|
|
340
340
|
private finalizeNavigation;
|
|
341
341
|
private handleBlockedRequestByContent;
|
|
342
342
|
private restoreRequestState;
|
|
343
|
-
|
|
343
|
+
private applyCookies;
|
|
344
344
|
/**
|
|
345
345
|
* Marks session bad on navigation timeout, and stops in-flight page loading on any navigation error.
|
|
346
346
|
*/
|
|
347
|
-
|
|
347
|
+
private handleNavigationTimeout;
|
|
348
348
|
/**
|
|
349
349
|
* Transforms proxy-related errors to `SessionError`.
|
|
350
350
|
*/
|
|
351
|
-
|
|
351
|
+
private throwIfProxyError;
|
|
352
352
|
protected abstract _navigationHandler(crawlingContext: BrowserCrawlingContext<Page, Response>, gotoOptions: GoToOptions): Promise<Context['response'] | null | undefined>;
|
|
353
353
|
private processResponse;
|
|
354
354
|
/**
|
|
@@ -247,15 +247,15 @@ export class BrowserCrawler extends BasicCrawler {
|
|
|
247
247
|
const gotoOptions = crawlingContext.gotoOptions;
|
|
248
248
|
const cookiesBeforeHooks = readContextField(crawlingContext, COOKIES_BEFORE_HOOKS);
|
|
249
249
|
const cookiesAfterHooks = this._getCookieHeaderFromRequest(crawlingContext.request);
|
|
250
|
-
await this.
|
|
250
|
+
await this.applyCookies(crawlingContext, cookiesBeforeHooks, cookiesAfterHooks);
|
|
251
251
|
let response;
|
|
252
252
|
try {
|
|
253
253
|
response = (await this._navigationHandler(crawlingContext, gotoOptions)) ?? undefined;
|
|
254
254
|
}
|
|
255
255
|
catch (error) {
|
|
256
|
-
await this.
|
|
256
|
+
await this.handleNavigationTimeout(crawlingContext, error);
|
|
257
257
|
crawlingContext.request.state = RequestState.ERROR;
|
|
258
|
-
this.
|
|
258
|
+
this.throwIfProxyError(error);
|
|
259
259
|
throw error;
|
|
260
260
|
}
|
|
261
261
|
tryCancel();
|
|
@@ -304,7 +304,7 @@ export class BrowserCrawler extends BasicCrawler {
|
|
|
304
304
|
crawlingContext.request.state = RequestState.REQUEST_HANDLER;
|
|
305
305
|
return {};
|
|
306
306
|
}
|
|
307
|
-
async
|
|
307
|
+
async applyCookies({ session, request, page }, preHooksCookies, postHooksCookies) {
|
|
308
308
|
const sessionCookie = session?.cookieJar.getCookiesSync(request.url).map(toughCookieToBrowserPoolCookie) ?? [];
|
|
309
309
|
const parsedPreHooksCookies = preHooksCookies.split(/ *; */).map((c) => cookieStringToToughCookie(c));
|
|
310
310
|
const parsedPostHooksCookies = postHooksCookies.split(/ *; */).map((c) => cookieStringToToughCookie(c));
|
|
@@ -316,7 +316,7 @@ export class BrowserCrawler extends BasicCrawler {
|
|
|
316
316
|
/**
|
|
317
317
|
* Marks session bad on navigation timeout, and stops in-flight page loading on any navigation error.
|
|
318
318
|
*/
|
|
319
|
-
async
|
|
319
|
+
async handleNavigationTimeout(crawlingContext, error) {
|
|
320
320
|
const { session, page } = crawlingContext;
|
|
321
321
|
if (error?.constructor.name === 'TimeoutError') {
|
|
322
322
|
handleRequestTimeout({ session, errorMessage: error.message });
|
|
@@ -328,7 +328,7 @@ export class BrowserCrawler extends BasicCrawler {
|
|
|
328
328
|
/**
|
|
329
329
|
* Transforms proxy-related errors to `SessionError`.
|
|
330
330
|
*/
|
|
331
|
-
|
|
331
|
+
throwIfProxyError(error) {
|
|
332
332
|
if (this.isProxyError(error)) {
|
|
333
333
|
throw new SessionError(this._getMessageFromError(error));
|
|
334
334
|
}
|
|
@@ -110,11 +110,11 @@ export declare abstract class BrowserLauncher<Plugin extends BrowserPlugin, Laun
|
|
|
110
110
|
*/
|
|
111
111
|
launch(): LaunchResult;
|
|
112
112
|
createLaunchOptions(): Dictionary;
|
|
113
|
-
protected
|
|
114
|
-
|
|
113
|
+
protected getDefaultHeadlessOption(): boolean;
|
|
114
|
+
private getChromeExecutablePath;
|
|
115
115
|
/**
|
|
116
116
|
* Gets a typical path to Chrome executable, depending on the current operating system.
|
|
117
117
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
private getTypicalChromeExecutablePath;
|
|
119
|
+
private validateProxyUrlProtocol;
|
|
120
120
|
}
|
|
@@ -54,7 +54,7 @@ export class BrowserLauncher {
|
|
|
54
54
|
constructor(launchContext, config = Configuration.getGlobalConfig()) {
|
|
55
55
|
this.config = config;
|
|
56
56
|
const { launcher, proxyUrl, useChrome, userAgent, launchOptions = {}, ...otherLaunchContextProps } = launchContext;
|
|
57
|
-
this.
|
|
57
|
+
this.validateProxyUrlProtocol(proxyUrl);
|
|
58
58
|
// those need to be reassigned otherwise they are {} in types
|
|
59
59
|
this.launcher = launcher;
|
|
60
60
|
this.proxyUrl = proxyUrl;
|
|
@@ -95,23 +95,23 @@ export class BrowserLauncher {
|
|
|
95
95
|
launchOptions.args.push(`--user-agent=${this.userAgent}`);
|
|
96
96
|
}
|
|
97
97
|
if (launchOptions.headless == null) {
|
|
98
|
-
launchOptions.headless = this.
|
|
98
|
+
launchOptions.headless = this.getDefaultHeadlessOption();
|
|
99
99
|
}
|
|
100
100
|
if (this.useChrome && !launchOptions.executablePath) {
|
|
101
|
-
launchOptions.executablePath = this.
|
|
101
|
+
launchOptions.executablePath = this.getChromeExecutablePath();
|
|
102
102
|
}
|
|
103
103
|
return launchOptions;
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
getDefaultHeadlessOption() {
|
|
106
106
|
return this.config.headless && !this.config.xvfb;
|
|
107
107
|
}
|
|
108
|
-
|
|
109
|
-
return this.config.chromeExecutablePath ?? this.
|
|
108
|
+
getChromeExecutablePath() {
|
|
109
|
+
return this.config.chromeExecutablePath ?? this.getTypicalChromeExecutablePath();
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* Gets a typical path to Chrome executable, depending on the current operating system.
|
|
113
113
|
*/
|
|
114
|
-
|
|
114
|
+
getTypicalChromeExecutablePath() {
|
|
115
115
|
/**
|
|
116
116
|
* Returns path of Chrome executable by its OS environment variable to deal with non-english language OS.
|
|
117
117
|
* Taking also into account the old [chrome 380177 issue](https://bugs.chromium.org/p/chromium/issues/detail?id=380177).
|
|
@@ -139,7 +139,7 @@ export class BrowserLauncher {
|
|
|
139
139
|
return '/usr/bin/google-chrome';
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
validateProxyUrlProtocol(proxyUrl) {
|
|
143
143
|
if (!proxyUrl)
|
|
144
144
|
return;
|
|
145
145
|
if (!/^(http|https|socks4|socks5)/i.test(proxyUrl)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/browser",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.81",
|
|
4
4
|
"description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.0.0"
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@apify/timeout": "^0.3.2",
|
|
51
|
-
"@crawlee/basic": "4.0.0-beta.
|
|
52
|
-
"@crawlee/browser-pool": "4.0.0-beta.
|
|
53
|
-
"@crawlee/types": "4.0.0-beta.
|
|
54
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
51
|
+
"@crawlee/basic": "4.0.0-beta.81",
|
|
52
|
+
"@crawlee/browser-pool": "4.0.0-beta.81",
|
|
53
|
+
"@crawlee/types": "4.0.0-beta.81",
|
|
54
|
+
"@crawlee/utils": "4.0.0-beta.81",
|
|
55
55
|
"ow": "^2.0.0",
|
|
56
56
|
"tslib": "^2.8.1",
|
|
57
57
|
"type-fest": "^4.41.0"
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "80dc6b4fc82237e63a51a71153809ec8dfd0cc50"
|
|
79
79
|
}
|