@crawlee/playwright 4.0.0-beta.85 → 4.0.0-beta.87
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.
- package/internals/adaptive-playwright-crawler.d.ts +3 -3
- package/internals/playwright-crawler.d.ts +6 -6
- package/internals/playwright-crawler.js +4 -1
- package/internals/playwright-launcher.d.ts +4 -4
- package/internals/playwright-launcher.js +10 -10
- package/internals/utils/playwright-utils.d.ts +2 -2
- package/internals/utils/playwright-utils.js +3 -3
- package/package.json +9 -9
|
@@ -83,7 +83,7 @@ type AdaptiveHook<ContextExtension = Dictionary<never>> = BrowserHook<AdaptiveHo
|
|
|
83
83
|
type AdaptivePostNavigationHook<ContextExtension = Dictionary<never>> = BrowserHook<Omit<AdaptiveHookContext, 'request'> & {
|
|
84
84
|
request: LoadedRequest<Request>;
|
|
85
85
|
}, ContextExtension>;
|
|
86
|
-
export interface AdaptivePlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension> extends Omit<BasicCrawlerOptions<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext>, 'preNavigationHooks' | 'postNavigationHooks'> {
|
|
86
|
+
export interface AdaptivePlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<AdaptivePlaywrightCrawlerContext['request']>>> extends Omit<BasicCrawlerOptions<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext, Routes>, 'preNavigationHooks' | 'postNavigationHooks'> {
|
|
87
87
|
/**
|
|
88
88
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies.
|
|
89
89
|
* The function accepts a subset of the crawling context. If you attempt to access the `page` property during HTTP-only crawling,
|
|
@@ -175,7 +175,7 @@ export interface AdaptivePlaywrightCrawlerOptions<ContextExtension = Dictionary<
|
|
|
175
175
|
*
|
|
176
176
|
* @experimental
|
|
177
177
|
*/
|
|
178
|
-
export declare class AdaptivePlaywrightCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension> extends BasicCrawler<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext> {
|
|
178
|
+
export declare class AdaptivePlaywrightCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends AdaptivePlaywrightCrawlerContext = AdaptivePlaywrightCrawlerContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<AdaptivePlaywrightCrawlerContext['request']>>> extends BasicCrawler<AdaptivePlaywrightCrawlerContext, ContextExtension, ExtendedContext, Routes> {
|
|
179
179
|
private renderingTypePredictor;
|
|
180
180
|
private resultChecker;
|
|
181
181
|
private shouldPropagateError;
|
|
@@ -188,7 +188,7 @@ export declare class AdaptivePlaywrightCrawler<ContextExtension = Dictionary<nev
|
|
|
188
188
|
private resultObjects;
|
|
189
189
|
private inFlightRenderingTypeDetections;
|
|
190
190
|
private teardownHooks;
|
|
191
|
-
constructor(options?: AdaptivePlaywrightCrawlerOptions<ContextExtension, ExtendedContext>);
|
|
191
|
+
constructor(options?: AdaptivePlaywrightCrawlerOptions<ContextExtension, ExtendedContext, Routes>);
|
|
192
192
|
protected _init(): Promise<void>;
|
|
193
193
|
protected buildContextPipeline(): ContextPipeline<CrawlingContext<Dictionary>, CrawlingContext<Dictionary> & {
|
|
194
194
|
readonly request: LoadedRequest<Request<Dictionary>>;
|
|
@@ -13,9 +13,9 @@ export interface PlaywrightCrawlingContext<UserData extends Dictionary = Diction
|
|
|
13
13
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
14
14
|
export interface PlaywrightHook extends BrowserHook<PlaywrightCrawlingContext> {
|
|
15
15
|
}
|
|
16
|
-
export interface PlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends PlaywrightCrawlingContext = PlaywrightCrawlingContext & ContextExtension> extends BrowserCrawlerOptions<Page, Response, PlaywrightCrawlingContext, ContextExtension, ExtendedContext, {
|
|
16
|
+
export interface PlaywrightCrawlerOptions<ContextExtension = Dictionary<never>, ExtendedContext extends PlaywrightCrawlingContext = PlaywrightCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<PlaywrightCrawlingContext['request']>>> extends BrowserCrawlerOptions<Page, Response, PlaywrightCrawlingContext, ContextExtension, ExtendedContext, {
|
|
17
17
|
browserPlugins: [PlaywrightPlugin];
|
|
18
|
-
}> {
|
|
18
|
+
}, Routes> {
|
|
19
19
|
/**
|
|
20
20
|
* The same options as used by {@link launchPlaywright}.
|
|
21
21
|
*/
|
|
@@ -42,7 +42,7 @@ export interface PlaywrightCrawlerOptions<ContextExtension = Dictionary<never>,
|
|
|
42
42
|
* The exceptions are logged to the request using the
|
|
43
43
|
* {@link Request.pushErrorMessage} function.
|
|
44
44
|
*/
|
|
45
|
-
requestHandler?: RequestHandler<ExtendedContext>;
|
|
45
|
+
requestHandler?: RouterHandler<ExtendedContext, Routes> | RequestHandler<ExtendedContext>;
|
|
46
46
|
/**
|
|
47
47
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies
|
|
48
48
|
* or browser properties before navigation. The function receives the `crawlingContext`; the options object
|
|
@@ -143,9 +143,9 @@ export interface PlaywrightCrawlerOptions<ContextExtension = Dictionary<never>,
|
|
|
143
143
|
* ```
|
|
144
144
|
* @category Crawlers
|
|
145
145
|
*/
|
|
146
|
-
export declare class PlaywrightCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends PlaywrightCrawlingContext = PlaywrightCrawlingContext & ContextExtension> extends BrowserCrawler<Page, Response, {
|
|
146
|
+
export declare class PlaywrightCrawler<ContextExtension = Dictionary<never>, ExtendedContext extends PlaywrightCrawlingContext = PlaywrightCrawlingContext & ContextExtension, Routes extends Record<keyof Routes, Dictionary> = Record<string, GetUserDataFromRequest<PlaywrightCrawlingContext['request']>>> extends BrowserCrawler<Page, Response, {
|
|
147
147
|
browserPlugins: [PlaywrightPlugin];
|
|
148
|
-
}, LaunchOptions, PlaywrightCrawlingContext, ContextExtension, ExtendedContext> {
|
|
148
|
+
}, LaunchOptions, PlaywrightCrawlingContext, ContextExtension, ExtendedContext, Routes> {
|
|
149
149
|
protected static optionsShape: {
|
|
150
150
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
151
151
|
browserPoolOptions: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
@@ -243,7 +243,7 @@ export declare class PlaywrightCrawler<ContextExtension = Dictionary<never>, Ext
|
|
|
243
243
|
/**
|
|
244
244
|
* All `PlaywrightCrawler` parameters are passed via an options object.
|
|
245
245
|
*/
|
|
246
|
-
constructor(options?: PlaywrightCrawlerOptions<ContextExtension, ExtendedContext>);
|
|
246
|
+
constructor(options?: PlaywrightCrawlerOptions<ContextExtension, ExtendedContext, Routes>);
|
|
247
247
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
248
248
|
protected buildContextPipeline(): import("@crawlee/browser").ContextPipeline<import("@crawlee/browser").CrawlingContext<Dictionary>, BrowserCrawlingContext<Page, Response, Dictionary, Dictionary> & {
|
|
249
249
|
injectFile: (filePath: string, options?: InjectFileOptions) => Promise<unknown>;
|
|
@@ -139,7 +139,10 @@ export class PlaywrightCrawler extends BrowserCrawler {
|
|
|
139
139
|
},
|
|
140
140
|
infiniteScroll: async (options) => playwrightUtils.infiniteScroll(context.page, options),
|
|
141
141
|
listDownloads: async () => downloads,
|
|
142
|
-
saveSnapshot: async (options) => playwrightUtils.saveSnapshot(context.page, {
|
|
142
|
+
saveSnapshot: async (options) => playwrightUtils.saveSnapshot(context.page, {
|
|
143
|
+
...options,
|
|
144
|
+
configuration: serviceLocator.getConfiguration(),
|
|
145
|
+
}),
|
|
143
146
|
enqueueLinksByClickingElements: async (options) => playwrightUtils.enqueueLinksByClickingElements({
|
|
144
147
|
...options,
|
|
145
148
|
page: context.page,
|
|
@@ -70,7 +70,7 @@ export interface PlaywrightLaunchContext extends BrowserLaunchContext<LaunchOpti
|
|
|
70
70
|
* @ignore
|
|
71
71
|
*/
|
|
72
72
|
export declare class PlaywrightLauncher extends BrowserLauncher<PlaywrightPlugin> {
|
|
73
|
-
readonly
|
|
73
|
+
readonly configuration: Configuration;
|
|
74
74
|
protected static optionsShape: {
|
|
75
75
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
76
76
|
launcher: import("ow").ObjectPredicate<object> & import("ow").BasePredicate<object | undefined>;
|
|
@@ -96,7 +96,7 @@ export declare class PlaywrightLauncher extends BrowserLauncher<PlaywrightPlugin
|
|
|
96
96
|
/**
|
|
97
97
|
* All `PlaywrightLauncher` parameters are passed via this launchContext object.
|
|
98
98
|
*/
|
|
99
|
-
constructor(launchContext?: PlaywrightLaunchContext,
|
|
99
|
+
constructor(launchContext?: PlaywrightLaunchContext, configuration?: Configuration);
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Launches headless browsers using Playwright pre-configured to work within the Apify platform.
|
|
@@ -127,8 +127,8 @@ export declare class PlaywrightLauncher extends BrowserLauncher<PlaywrightPlugin
|
|
|
127
127
|
* Optional settings passed to `browserType.launch()`. In addition to
|
|
128
128
|
* [Playwright's options](https://playwright.dev/docs/api/class-browsertype?_highlight=launch#browsertypelaunchoptions)
|
|
129
129
|
* the object may contain our own {@link PlaywrightLaunchContext} that enable additional features.
|
|
130
|
-
* @param [
|
|
130
|
+
* @param [configuration]
|
|
131
131
|
* @returns
|
|
132
132
|
* Promise that resolves to Playwright's `Browser` instance.
|
|
133
133
|
*/
|
|
134
|
-
export declare function launchPlaywright(launchContext?: PlaywrightLaunchContext,
|
|
134
|
+
export declare function launchPlaywright(launchContext?: PlaywrightLaunchContext, configuration?: Configuration): Promise<Browser>;
|
|
@@ -6,7 +6,7 @@ import ow from 'ow';
|
|
|
6
6
|
* @ignore
|
|
7
7
|
*/
|
|
8
8
|
export class PlaywrightLauncher extends BrowserLauncher {
|
|
9
|
-
|
|
9
|
+
configuration;
|
|
10
10
|
static optionsShape = {
|
|
11
11
|
...BrowserLauncher.optionsShape,
|
|
12
12
|
launcher: ow.optional.object,
|
|
@@ -15,7 +15,7 @@ export class PlaywrightLauncher extends BrowserLauncher {
|
|
|
15
15
|
/**
|
|
16
16
|
* All `PlaywrightLauncher` parameters are passed via this launchContext object.
|
|
17
17
|
*/
|
|
18
|
-
constructor(launchContext = {},
|
|
18
|
+
constructor(launchContext = {}, configuration = Configuration.getGlobalConfiguration()) {
|
|
19
19
|
ow(launchContext, 'PlaywrightLauncherOptions', ow.object.exactShape(PlaywrightLauncher.optionsShape));
|
|
20
20
|
const { launcher = BrowserLauncher.requireLauncherOrThrow('playwright', 'apify/actor-node-playwright-*').chromium, } = launchContext;
|
|
21
21
|
const { launchOptions = {}, ...rest } = launchContext;
|
|
@@ -23,11 +23,11 @@ export class PlaywrightLauncher extends BrowserLauncher {
|
|
|
23
23
|
...rest,
|
|
24
24
|
launchOptions: {
|
|
25
25
|
...launchOptions,
|
|
26
|
-
executablePath: getDefaultExecutablePath(launchContext,
|
|
26
|
+
executablePath: getDefaultExecutablePath(launchContext, configuration),
|
|
27
27
|
},
|
|
28
28
|
launcher,
|
|
29
|
-
},
|
|
30
|
-
this.
|
|
29
|
+
}, configuration);
|
|
30
|
+
this.configuration = configuration;
|
|
31
31
|
this.Plugin = PlaywrightPlugin;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -36,8 +36,8 @@ export class PlaywrightLauncher extends BrowserLauncher {
|
|
|
36
36
|
* @returns default path to browser.
|
|
37
37
|
* @ignore
|
|
38
38
|
*/
|
|
39
|
-
function getDefaultExecutablePath(launchContext,
|
|
40
|
-
const pathFromPlaywrightImage =
|
|
39
|
+
function getDefaultExecutablePath(launchContext, configuration) {
|
|
40
|
+
const pathFromPlaywrightImage = configuration.defaultBrowserPath;
|
|
41
41
|
const { launchOptions = {} } = launchContext;
|
|
42
42
|
if (launchOptions.executablePath) {
|
|
43
43
|
return launchOptions.executablePath;
|
|
@@ -79,11 +79,11 @@ function getDefaultExecutablePath(launchContext, config) {
|
|
|
79
79
|
* Optional settings passed to `browserType.launch()`. In addition to
|
|
80
80
|
* [Playwright's options](https://playwright.dev/docs/api/class-browsertype?_highlight=launch#browsertypelaunchoptions)
|
|
81
81
|
* the object may contain our own {@link PlaywrightLaunchContext} that enable additional features.
|
|
82
|
-
* @param [
|
|
82
|
+
* @param [configuration]
|
|
83
83
|
* @returns
|
|
84
84
|
* Promise that resolves to Playwright's `Browser` instance.
|
|
85
85
|
*/
|
|
86
|
-
export async function launchPlaywright(launchContext,
|
|
87
|
-
const playwrightLauncher = new PlaywrightLauncher(launchContext,
|
|
86
|
+
export async function launchPlaywright(launchContext, configuration = Configuration.getGlobalConfiguration()) {
|
|
87
|
+
const playwrightLauncher = new PlaywrightLauncher(launchContext, configuration);
|
|
88
88
|
return playwrightLauncher.launch();
|
|
89
89
|
}
|
|
@@ -265,9 +265,9 @@ export interface SaveSnapshotOptions {
|
|
|
265
265
|
keyValueStoreName?: string | null;
|
|
266
266
|
/**
|
|
267
267
|
* Configuration of the crawler that will be used to save the snapshot.
|
|
268
|
-
* @default Configuration.
|
|
268
|
+
* @default Configuration.getGlobalConfiguration()
|
|
269
269
|
*/
|
|
270
|
-
|
|
270
|
+
configuration?: Configuration;
|
|
271
271
|
}
|
|
272
272
|
/**
|
|
273
273
|
* Saves a full screenshot and HTML of the current page into a Key-Value store.
|
|
@@ -357,12 +357,12 @@ export async function saveSnapshot(page, options = {}) {
|
|
|
357
357
|
saveScreenshot: ow.optional.boolean,
|
|
358
358
|
saveHtml: ow.optional.boolean,
|
|
359
359
|
keyValueStoreName: ow.optional.string,
|
|
360
|
-
|
|
360
|
+
configuration: ow.optional.object,
|
|
361
361
|
}));
|
|
362
|
-
const { key = 'SNAPSHOT', screenshotQuality = 50, saveScreenshot = true, saveHtml = true, keyValueStoreName,
|
|
362
|
+
const { key = 'SNAPSHOT', screenshotQuality = 50, saveScreenshot = true, saveHtml = true, keyValueStoreName, configuration, } = options;
|
|
363
363
|
try {
|
|
364
364
|
const store = await KeyValueStore.open(keyValueStoreName ? { name: keyValueStoreName } : null, {
|
|
365
|
-
|
|
365
|
+
configuration: configuration ?? Configuration.getGlobalConfiguration(),
|
|
366
366
|
});
|
|
367
367
|
if (saveScreenshot) {
|
|
368
368
|
const screenshotName = `${key}.jpg`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/playwright",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.87",
|
|
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"
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@apify/datastructures": "^2.0.3",
|
|
51
51
|
"@apify/timeout": "^0.3.2",
|
|
52
|
-
"@crawlee/basic": "4.0.0-beta.
|
|
53
|
-
"@crawlee/browser": "4.0.0-beta.
|
|
54
|
-
"@crawlee/browser-pool": "4.0.0-beta.
|
|
55
|
-
"@crawlee/cheerio": "4.0.0-beta.
|
|
56
|
-
"@crawlee/core": "4.0.0-beta.
|
|
57
|
-
"@crawlee/types": "4.0.0-beta.
|
|
58
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
52
|
+
"@crawlee/basic": "4.0.0-beta.87",
|
|
53
|
+
"@crawlee/browser": "4.0.0-beta.87",
|
|
54
|
+
"@crawlee/browser-pool": "4.0.0-beta.87",
|
|
55
|
+
"@crawlee/cheerio": "4.0.0-beta.87",
|
|
56
|
+
"@crawlee/core": "4.0.0-beta.87",
|
|
57
|
+
"@crawlee/types": "4.0.0-beta.87",
|
|
58
|
+
"@crawlee/utils": "4.0.0-beta.87",
|
|
59
59
|
"cheerio": "^1.0.0",
|
|
60
60
|
"idcac-playwright": "^0.1.3",
|
|
61
61
|
"jquery": "^3.7.1",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "1b7604cd77b694460aac4448b4555444fa1b2bdb"
|
|
89
89
|
}
|