@crawlee/playwright 4.0.0-beta.223 → 4.0.0-beta.224
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.
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import type { Configuration } from '@crawlee/browser';
|
|
2
|
-
import type { BrowserPool, BrowserPoolHooks, BrowserPoolOptions, PlaywrightPlugin
|
|
1
|
+
import type { Configuration, CrawlerRemoteBrowserOptions } from '@crawlee/browser';
|
|
2
|
+
import type { BrowserPool, BrowserPoolHooks, BrowserPoolOptions, PlaywrightPlugin } from '@crawlee/browser-pool';
|
|
3
3
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
4
4
|
import type { Page } from 'playwright';
|
|
5
5
|
import type { PlaywrightLaunchContext } from './playwright-launcher.js';
|
|
6
|
+
/** {@link BrowserCrawlerOptions.remoteBrowser|`remoteBrowser`} for Playwright, with the protocol to connect over. */
|
|
7
|
+
export interface PlaywrightRemoteBrowserOptions extends CrawlerRemoteBrowserOptions {
|
|
8
|
+
/**
|
|
9
|
+
* `'cdp'` uses `connectOverCDP()` (the default), `'playwright'` uses `connect()` (Playwright's own WebSocket
|
|
10
|
+
* protocol, for endpoints started with `launchServer()`).
|
|
11
|
+
*/
|
|
12
|
+
protocol?: 'cdp' | 'playwright';
|
|
13
|
+
}
|
|
6
14
|
/** A {@link BrowserPool} of Playwright browsers, as built by {@link playwrightBrowserPool}. */
|
|
7
15
|
export type PlaywrightBrowserPool = BrowserPool<{
|
|
8
16
|
browserPlugins: [PlaywrightPlugin];
|
|
@@ -17,8 +25,8 @@ export interface PlaywrightBrowserPoolOptions extends Omit<BrowserPoolOptions, '
|
|
|
17
25
|
headless?: boolean;
|
|
18
26
|
/** Configuration to read the browser defaults from. Defaults to the global configuration. */
|
|
19
27
|
configuration?: Configuration;
|
|
20
|
-
}
|
|
21
|
-
|
|
28
|
+
/** Connect to a remote browser service instead of launching locally; see {@link BrowserCrawlerOptions.remoteBrowser}. */
|
|
29
|
+
remoteBrowser?: PlaywrightRemoteBrowserOptions;
|
|
22
30
|
}
|
|
23
31
|
/**
|
|
24
32
|
* Builds a {@link BrowserPool} of Playwright browsers to pass to a {@link PlaywrightCrawler} as its
|
|
@@ -45,27 +53,3 @@ export interface RemotePlaywrightBrowserPoolOptions extends Pick<PlaywrightBrows
|
|
|
45
53
|
* @category Browser management
|
|
46
54
|
*/
|
|
47
55
|
export declare function playwrightBrowserPool(options?: PlaywrightBrowserPoolOptions): PlaywrightBrowserPool;
|
|
48
|
-
/**
|
|
49
|
-
* The {@link RemoteBrowserPool} counterpart of {@link playwrightBrowserPool}: connects to a remote browser
|
|
50
|
-
* service (Browserbase, Browserless, Steel, ...) with a Playwright plugin derived from `launchContext`.
|
|
51
|
-
*
|
|
52
|
-
* A {@link PlaywrightCrawler} accepts the same connection details directly via
|
|
53
|
-
* {@link BrowserCrawlerOptions.remoteBrowser|`remoteBrowser`}; reach for this factory when you also need to
|
|
54
|
-
* tune the wrapping pool, or to share one remote pool between crawlers.
|
|
55
|
-
*
|
|
56
|
-
* **Example usage:**
|
|
57
|
-
*
|
|
58
|
-
* ```javascript
|
|
59
|
-
* const crawler = new PlaywrightCrawler({
|
|
60
|
-
* browserPool: remotePlaywrightBrowserPool({
|
|
61
|
-
* endpoint: 'wss://production-sfo.browserless.io?token=xxx',
|
|
62
|
-
* maxOpenBrowsers: 2,
|
|
63
|
-
* browserPoolOptions: { useFingerprints: false },
|
|
64
|
-
* }),
|
|
65
|
-
* requestHandler: async ({ page }) => { ... },
|
|
66
|
-
* });
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* @category Browser management
|
|
70
|
-
*/
|
|
71
|
-
export declare function remotePlaywrightBrowserPool(options: RemotePlaywrightBrowserPoolOptions): RemoteBrowserPool<Page>;
|
|
@@ -27,33 +27,6 @@ export function playwrightBrowserPool(options = {}) {
|
|
|
27
27
|
const { launchContext, headless, configuration, ...poolOptions } = options;
|
|
28
28
|
return playwrightLauncher(launchContext, headless, configuration).createBrowserPool(poolOptions);
|
|
29
29
|
}
|
|
30
|
-
/**
|
|
31
|
-
* The {@link RemoteBrowserPool} counterpart of {@link playwrightBrowserPool}: connects to a remote browser
|
|
32
|
-
* service (Browserbase, Browserless, Steel, ...) with a Playwright plugin derived from `launchContext`.
|
|
33
|
-
*
|
|
34
|
-
* A {@link PlaywrightCrawler} accepts the same connection details directly via
|
|
35
|
-
* {@link BrowserCrawlerOptions.remoteBrowser|`remoteBrowser`}; reach for this factory when you also need to
|
|
36
|
-
* tune the wrapping pool, or to share one remote pool between crawlers.
|
|
37
|
-
*
|
|
38
|
-
* **Example usage:**
|
|
39
|
-
*
|
|
40
|
-
* ```javascript
|
|
41
|
-
* const crawler = new PlaywrightCrawler({
|
|
42
|
-
* browserPool: remotePlaywrightBrowserPool({
|
|
43
|
-
* endpoint: 'wss://production-sfo.browserless.io?token=xxx',
|
|
44
|
-
* maxOpenBrowsers: 2,
|
|
45
|
-
* browserPoolOptions: { useFingerprints: false },
|
|
46
|
-
* }),
|
|
47
|
-
* requestHandler: async ({ page }) => { ... },
|
|
48
|
-
* });
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* @category Browser management
|
|
52
|
-
*/
|
|
53
|
-
export function remotePlaywrightBrowserPool(options) {
|
|
54
|
-
const { launchContext, headless, configuration, ...remoteOptions } = options;
|
|
55
|
-
return playwrightLauncher(launchContext, headless, configuration).createRemoteBrowserPool(remoteOptions);
|
|
56
|
-
}
|
|
57
30
|
function playwrightLauncher(launchContext = {}, headless, configuration) {
|
|
58
31
|
return new PlaywrightLauncher(headless == null
|
|
59
32
|
? launchContext
|
|
@@ -4,6 +4,7 @@ import type { Dictionary } from '@crawlee/types';
|
|
|
4
4
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
5
5
|
import type { Page, Response } from 'playwright';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
+
import { type PlaywrightRemoteBrowserOptions } from './playwright-browser-pool.js';
|
|
7
8
|
import type { PlaywrightLaunchContext } from './playwright-launcher.js';
|
|
8
9
|
import type { DirectNavigationOptions, HandleCloudflareChallengeOptions, PlaywrightContextUtils } from './utils/playwright-utils.js';
|
|
9
10
|
export type PlaywrightGotoOptions = NonNullable<Parameters<Page['goto']>[1]>;
|
|
@@ -20,6 +21,8 @@ export interface PlaywrightCrawlerOptions<ContextExtension = Dictionary<never>,
|
|
|
20
21
|
* Can be also set via {@link Configuration}.
|
|
21
22
|
*/
|
|
22
23
|
headless?: boolean;
|
|
24
|
+
/** See {@link BrowserCrawlerOptions.remoteBrowser}; Playwright additionally lets you pick the `protocol`. */
|
|
25
|
+
remoteBrowser?: PlaywrightRemoteBrowserOptions;
|
|
23
26
|
/**
|
|
24
27
|
* Async functions that are sequentially evaluated before the navigation. Good for setting additional cookies
|
|
25
28
|
* or browser properties before navigation. The function receives the `crawlingContext`; the options object
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BrowserCrawler, RequestState, Router, serviceLocator } from '@crawlee/browser';
|
|
2
2
|
import { assertBrowserPoolNotConfigured, parseArgument, schemas } from '@crawlee/utils/internal';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { playwrightBrowserPool
|
|
4
|
+
import { playwrightBrowserPool } from './playwright-browser-pool.js';
|
|
5
5
|
import { blockRequests, compileScript, enqueueLinksByClickingElements, gotoExtended, handleCloudflareChallenge, infiniteScroll, injectFile, injectJQuery, parseWithCheerio, saveSnapshot, } from './utils/playwright-utils.js';
|
|
6
6
|
/**
|
|
7
7
|
* Provides a simple framework for parallel crawling of web pages
|
|
@@ -99,9 +99,7 @@ export class PlaywrightCrawler extends BrowserCrawler {
|
|
|
99
99
|
super({
|
|
100
100
|
...browserCrawlerOptions,
|
|
101
101
|
configuration,
|
|
102
|
-
browserPoolBuilder: (remoteBrowser) => remoteBrowser
|
|
103
|
-
? remotePlaywrightBrowserPool({ ...remoteBrowser, launchContext, headless, configuration })
|
|
104
|
-
: playwrightBrowserPool({ launchContext, headless, configuration }),
|
|
102
|
+
browserPoolBuilder: (remoteBrowser) => playwrightBrowserPool({ launchContext, headless, configuration, remoteBrowser }),
|
|
105
103
|
contextPipelineBuilder: () => this.#buildContextPipeline(),
|
|
106
104
|
});
|
|
107
105
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BrowserLauncher, Configuration } from '@crawlee/browser';
|
|
2
|
-
import { PlaywrightPlugin } from '@crawlee/browser-pool';
|
|
2
|
+
import { PlaywrightPlugin, RemotePlaywrightPlugin } from '@crawlee/browser-pool';
|
|
3
3
|
import { parseArgument, schemas } from '@crawlee/utils/internal';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
/**
|
|
@@ -35,6 +35,7 @@ export class PlaywrightLauncher extends BrowserLauncher {
|
|
|
35
35
|
}, configuration);
|
|
36
36
|
this.configuration = configuration;
|
|
37
37
|
this.Plugin = PlaywrightPlugin;
|
|
38
|
+
this.RemotePlugin = RemotePlaywrightPlugin;
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
/**
|
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.224",
|
|
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.13.0"
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@apify/datastructures": "^3.0.1",
|
|
51
51
|
"@apify/timeout": "^1.0.1",
|
|
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.224",
|
|
53
|
+
"@crawlee/browser": "4.0.0-beta.224",
|
|
54
|
+
"@crawlee/browser-pool": "4.0.0-beta.224",
|
|
55
|
+
"@crawlee/cheerio": "4.0.0-beta.224",
|
|
56
|
+
"@crawlee/core": "4.0.0-beta.224",
|
|
57
|
+
"@crawlee/types": "4.0.0-beta.224",
|
|
58
|
+
"@crawlee/utils": "4.0.0-beta.224",
|
|
59
59
|
"cheerio": "^1.0.0",
|
|
60
60
|
"jquery": "^3.7.1",
|
|
61
61
|
"ml-logistic-regression": "^2.0.0",
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "669f726126327dee3b1d6b950663fd4fceace651"
|
|
83
83
|
}
|