@crawlee/browser 4.0.0-beta.81 → 4.0.0-beta.82
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.
|
@@ -31,8 +31,8 @@ export interface BrowserCrawlingContext<Page extends CommonPage = CommonPage, Re
|
|
|
31
31
|
*/
|
|
32
32
|
enqueueLinks: (options?: EnqueueLinksOptions) => Promise<BatchAddRequestsResult>;
|
|
33
33
|
}
|
|
34
|
-
export type BrowserHook<Context = BrowserCrawlingContext> = (crawlingContext: Context) => Awaitable<void | Partial<Context>>;
|
|
35
|
-
export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Response extends BaseResponse = BaseResponse, Context extends BrowserCrawlingContext<Page, Response, Dictionary> = BrowserCrawlingContext<Page, Response, Dictionary>, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension, InternalBrowserPoolOptions extends BrowserPoolOptions = BrowserPoolOptions, __BrowserPlugins extends BrowserPlugin[] = InferBrowserPluginArray<InternalBrowserPoolOptions['browserPlugins']>, __BrowserControllerReturn extends BrowserController = ReturnType<__BrowserPlugins[number]['createController']>, __LaunchContextReturn extends LaunchContext = ReturnType<__BrowserPlugins[number]['createLaunchContext']>> extends Omit<BasicCrawlerOptions<Context, ExtendedContext>, 'requestHandler' | 'failedRequestHandler' | 'errorHandler'> {
|
|
34
|
+
export type BrowserHook<Context = BrowserCrawlingContext, ContextExtension = {}> = (crawlingContext: Context & ContextExtension) => Awaitable<void | Partial<Context>>;
|
|
35
|
+
export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Response extends BaseResponse = BaseResponse, Context extends BrowserCrawlingContext<Page, Response, Dictionary> = BrowserCrawlingContext<Page, Response, Dictionary>, ContextExtension = Dictionary<never>, ExtendedContext extends Context = Context & ContextExtension, InternalBrowserPoolOptions extends BrowserPoolOptions = BrowserPoolOptions, __BrowserPlugins extends BrowserPlugin[] = InferBrowserPluginArray<InternalBrowserPoolOptions['browserPlugins']>, __BrowserControllerReturn extends BrowserController = ReturnType<__BrowserPlugins[number]['createController']>, __LaunchContextReturn extends LaunchContext = ReturnType<__BrowserPlugins[number]['createLaunchContext']>> extends Omit<BasicCrawlerOptions<Context, ContextExtension, ExtendedContext>, 'requestHandler' | 'failedRequestHandler' | 'errorHandler'> {
|
|
36
36
|
launchContext?: BrowserLaunchContext<any, any>;
|
|
37
37
|
/**
|
|
38
38
|
* An existing browser pool instance to use. When provided, the crawler will use this pool directly instead of
|
|
@@ -124,8 +124,13 @@ export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Res
|
|
|
124
124
|
*
|
|
125
125
|
* A hook may optionally return a partial object whose properties are merged into the crawling context,
|
|
126
126
|
* allowing the hook to override context members for subsequent hooks and pipeline stages.
|
|
127
|
+
*
|
|
128
|
+
* The context is built up in the following order: base context (`request`, `session`, helpers, ...) ->
|
|
129
|
+
* `extendContext` -> `preNavigationHooks` -> navigation -> `postNavigationHooks` -> `requestHandler`.
|
|
130
|
+
* This means the members added by `extendContext` are already available here, but navigation-dependent
|
|
131
|
+
* members (e.g. `page`, `response`) are not.
|
|
127
132
|
*/
|
|
128
|
-
preNavigationHooks?: BrowserHook<Context>[];
|
|
133
|
+
preNavigationHooks?: BrowserHook<Context, ContextExtension>[];
|
|
129
134
|
/**
|
|
130
135
|
* Async functions that are sequentially evaluated after the navigation. Good for checking if the navigation was successful.
|
|
131
136
|
* The function accepts `crawlingContext` as the only parameter.
|
|
@@ -151,7 +156,7 @@ export interface BrowserCrawlerOptions<Page extends CommonPage = CommonPage, Res
|
|
|
151
156
|
* ]
|
|
152
157
|
* ```
|
|
153
158
|
*/
|
|
154
|
-
postNavigationHooks?: BrowserHook<Context>[];
|
|
159
|
+
postNavigationHooks?: BrowserHook<Context, ContextExtension>[];
|
|
155
160
|
/**
|
|
156
161
|
* Timeout in which page navigation needs to finish, in seconds.
|
|
157
162
|
*/
|
|
@@ -104,10 +104,13 @@ export class BrowserCrawler extends BasicCrawler {
|
|
|
104
104
|
.compose({ action: this.handleBlockedRequestByContent.bind(this) })
|
|
105
105
|
.compose({ action: this.restoreRequestState.bind(this) });
|
|
106
106
|
},
|
|
107
|
-
extendContext
|
|
107
|
+
extendContext,
|
|
108
108
|
});
|
|
109
109
|
this.launchContext = launchContext;
|
|
110
110
|
this.navigationTimeoutMillis = navigationTimeoutSecs * 1000;
|
|
111
|
+
// The public option hooks are extension-aware; internal storage uses the base context type
|
|
112
|
+
// (the pipeline composes hooks against the concrete context, which does not statically carry
|
|
113
|
+
// `ContextExtension`). The extension members are present at runtime regardless.
|
|
111
114
|
this.preNavigationHooks = preNavigationHooks;
|
|
112
115
|
this.postNavigationHooks = postNavigationHooks;
|
|
113
116
|
this.ignoreIframes = ignoreIframes;
|
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.82",
|
|
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.82",
|
|
52
|
+
"@crawlee/browser-pool": "4.0.0-beta.82",
|
|
53
|
+
"@crawlee/types": "4.0.0-beta.82",
|
|
54
|
+
"@crawlee/utils": "4.0.0-beta.82",
|
|
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": "eb1096f7c7743d124375ef011fbbadb19476822e"
|
|
79
79
|
}
|