@crawlee/browser-pool 3.0.0-alpha.9 → 3.0.0-beta.2
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/README.md +2 -0
- package/abstract-classes/browser-controller.d.ts +153 -0
- package/abstract-classes/browser-controller.d.ts.map +1 -0
- package/abstract-classes/browser-controller.js +230 -0
- package/abstract-classes/browser-controller.js.map +1 -0
- package/abstract-classes/browser-plugin.d.ts +102 -0
- package/abstract-classes/browser-plugin.d.ts.map +1 -0
- package/abstract-classes/browser-plugin.js +154 -0
- package/abstract-classes/browser-plugin.js.map +1 -0
- package/abstract-classes/utils.d.ts +2 -0
- package/abstract-classes/utils.d.ts.map +1 -0
- package/abstract-classes/utils.js +8 -0
- package/abstract-classes/utils.js.map +1 -0
- package/anonymize-proxy.d.ts +4 -0
- package/anonymize-proxy.d.ts.map +1 -0
- package/anonymize-proxy.js +34 -0
- package/anonymize-proxy.js.map +1 -0
- package/browser-pool.d.ts +406 -0
- package/browser-pool.d.ts.map +1 -0
- package/browser-pool.js +583 -0
- package/browser-pool.js.map +1 -0
- package/events.d.ts +11 -0
- package/events.d.ts.map +1 -0
- package/events.js +17 -0
- package/events.js.map +1 -0
- package/fingerprinting/hooks.d.ts +17 -0
- package/fingerprinting/hooks.d.ts.map +1 -0
- package/fingerprinting/hooks.js +87 -0
- package/fingerprinting/hooks.js.map +1 -0
- package/fingerprinting/types.d.ts +33 -0
- package/fingerprinting/types.d.ts.map +1 -0
- package/fingerprinting/types.js +21 -0
- package/fingerprinting/types.js.map +1 -0
- package/fingerprinting/utils.d.ts +4 -0
- package/fingerprinting/utils.d.ts.map +1 -0
- package/fingerprinting/utils.js +47 -0
- package/fingerprinting/utils.js.map +1 -0
- package/index.d.ts +37 -0
- package/index.d.ts.map +1 -0
- package/index.js.map +1 -0
- package/index.mjs +11 -0
- package/launch-context.d.ts +68 -0
- package/launch-context.d.ts.map +1 -0
- package/launch-context.js +94 -0
- package/launch-context.js.map +1 -0
- package/logger.d.ts +2 -0
- package/logger.d.ts.map +1 -0
- package/logger.js +9 -0
- package/logger.js.map +1 -0
- package/package.json +6 -9
- package/playwright/browser.d.ts +27 -0
- package/playwright/browser.d.ts.map +1 -0
- package/playwright/browser.js +66 -0
- package/playwright/browser.js.map +1 -0
- package/playwright/playwright-controller.d.ts +12 -0
- package/playwright/playwright-controller.d.ts.map +1 -0
- package/playwright/playwright-controller.js +71 -0
- package/playwright/playwright-controller.js.map +1 -0
- package/playwright/playwright-plugin.d.ts +13 -0
- package/playwright/playwright-plugin.d.ts.map +1 -0
- package/playwright/playwright-plugin.js +89 -0
- package/playwright/playwright-plugin.js.map +1 -0
- package/proxy-server.d.ts +2 -0
- package/proxy-server.d.ts.map +1 -0
- package/proxy-server.js +18 -0
- package/proxy-server.js.map +1 -0
- package/puppeteer/puppeteer-controller.d.ts +11 -0
- package/puppeteer/puppeteer-controller.d.ts.map +1 -0
- package/puppeteer/puppeteer-controller.js +112 -0
- package/puppeteer/puppeteer-controller.js.map +1 -0
- package/puppeteer/puppeteer-plugin.d.ts +12 -0
- package/puppeteer/puppeteer-plugin.d.ts.map +1 -0
- package/puppeteer/puppeteer-plugin.js +151 -0
- package/puppeteer/puppeteer-plugin.js.map +1 -0
- package/puppeteer/puppeteer-proxy-per-page.d.ts +27 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/utils.d.ts +6 -0
- package/utils.d.ts.map +1 -0
- package/utils.js +6 -0
- package/utils.js.map +1 -0
package/README.md
CHANGED
|
@@ -18,6 +18,8 @@ running on the [Apify Cloud](https://apify.com/).
|
|
|
18
18
|
|
|
19
19
|
**View full documentation, guides and examples on the [Apify SDK project website](https://sdk.apify.com)**
|
|
20
20
|
|
|
21
|
+
> Would you like to work with us on Apify SDK or similar projects? [We are hiring!](https://apify.com/jobs#senior-node.js-engineer)
|
|
22
|
+
|
|
21
23
|
## Motivation
|
|
22
24
|
|
|
23
25
|
Thanks to tools like [Playwright](https://github.com/microsoft/playwright), [Puppeteer](https://github.com/puppeteer/puppeteer) or
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { TypedEmitter } from 'tiny-typed-emitter';
|
|
2
|
+
import { BROWSER_CONTROLLER_EVENTS } from '../events';
|
|
3
|
+
import { LaunchContext } from '../launch-context';
|
|
4
|
+
import { UnwrapPromise } from '../utils';
|
|
5
|
+
import { BrowserPlugin, CommonBrowser, CommonLibrary } from './browser-plugin';
|
|
6
|
+
export interface BrowserControllerEvents<Library extends CommonLibrary, LibraryOptions = Parameters<Library['launch']>[0], LaunchResult extends CommonBrowser = UnwrapPromise<ReturnType<Library['launch']>>, NewPageOptions = Parameters<LaunchResult['newPage']>[0], NewPageResult = UnwrapPromise<ReturnType<LaunchResult['newPage']>>> {
|
|
7
|
+
[BROWSER_CONTROLLER_EVENTS.BROWSER_CLOSED]: (controller: BrowserController<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface Cookie {
|
|
10
|
+
/**
|
|
11
|
+
* Cookie name.
|
|
12
|
+
*/
|
|
13
|
+
name: string;
|
|
14
|
+
/**
|
|
15
|
+
* Cookie value.
|
|
16
|
+
*/
|
|
17
|
+
value: string;
|
|
18
|
+
/**
|
|
19
|
+
* The request-URI to associate with the setting of the cookie. This value can affect the
|
|
20
|
+
* default domain, path, source port, and source scheme values of the created cookie.
|
|
21
|
+
*/
|
|
22
|
+
url?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Cookie domain.
|
|
25
|
+
*/
|
|
26
|
+
domain?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Cookie path.
|
|
29
|
+
*/
|
|
30
|
+
path?: string;
|
|
31
|
+
/**
|
|
32
|
+
* True if cookie is secure.
|
|
33
|
+
*/
|
|
34
|
+
secure?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* True if cookie is http-only.
|
|
37
|
+
*/
|
|
38
|
+
httpOnly?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Cookie SameSite type.
|
|
41
|
+
*/
|
|
42
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
43
|
+
/**
|
|
44
|
+
* Cookie expiration date, session cookie if not set
|
|
45
|
+
*/
|
|
46
|
+
expires?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Cookie Priority.
|
|
49
|
+
*/
|
|
50
|
+
priority?: 'Low' | 'Medium' | 'High';
|
|
51
|
+
/**
|
|
52
|
+
* True if cookie is SameParty.
|
|
53
|
+
*/
|
|
54
|
+
sameParty?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Cookie source scheme type.
|
|
57
|
+
*/
|
|
58
|
+
sourceScheme?: 'Unset' | 'NonSecure' | 'Secure';
|
|
59
|
+
/**
|
|
60
|
+
* Cookie source port. Valid values are {-1, [1, 65535]}, -1 indicates an unspecified port.
|
|
61
|
+
* An unspecified port value allows protocol clients to emulate legacy cookie scope for the port.
|
|
62
|
+
* This is a temporary ability and it will be removed in the future.
|
|
63
|
+
*/
|
|
64
|
+
sourcePort?: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The `BrowserController` serves two purposes. First, it is the base class that
|
|
68
|
+
* specialized controllers like `PuppeteerController` or `PlaywrightController`
|
|
69
|
+
* extend. Second, it defines the public interface of the specialized classes
|
|
70
|
+
* which provide only private methods. Therefore, we do not keep documentation
|
|
71
|
+
* for the specialized classes, because it's the same for all of them.
|
|
72
|
+
* @hideconstructor
|
|
73
|
+
*/
|
|
74
|
+
export declare abstract class BrowserController<Library extends CommonLibrary = CommonLibrary, LibraryOptions = Parameters<Library['launch']>[0], LaunchResult extends CommonBrowser = UnwrapPromise<ReturnType<Library['launch']>>, NewPageOptions = Parameters<LaunchResult['newPage']>[0], NewPageResult = UnwrapPromise<ReturnType<LaunchResult['newPage']>>> extends TypedEmitter<BrowserControllerEvents<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>> {
|
|
75
|
+
id: string;
|
|
76
|
+
/**
|
|
77
|
+
* The `BrowserPlugin` instance used to launch the browser.
|
|
78
|
+
*/
|
|
79
|
+
browserPlugin: BrowserPlugin<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Browser representation of the underlying automation library.
|
|
82
|
+
*/
|
|
83
|
+
browser: LaunchResult;
|
|
84
|
+
/**
|
|
85
|
+
* The configuration the browser was launched with.
|
|
86
|
+
*/
|
|
87
|
+
launchContext: LaunchContext<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>;
|
|
88
|
+
isActive: boolean;
|
|
89
|
+
activePages: number;
|
|
90
|
+
totalPages: number;
|
|
91
|
+
lastPageOpenedAt: number;
|
|
92
|
+
private _activate;
|
|
93
|
+
private isActivePromise;
|
|
94
|
+
private commitBrowser;
|
|
95
|
+
private hasBrowserPromise;
|
|
96
|
+
constructor(browserPlugin: BrowserPlugin<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>);
|
|
97
|
+
/**
|
|
98
|
+
* Activates the BrowserController. If you try to open new pages before
|
|
99
|
+
* activation, the pages will get queued and will only be opened after
|
|
100
|
+
* activate is called.
|
|
101
|
+
* @ignore
|
|
102
|
+
*/
|
|
103
|
+
activate(): void;
|
|
104
|
+
/**
|
|
105
|
+
* @ignore
|
|
106
|
+
*/
|
|
107
|
+
assignBrowser(browser: LaunchResult, launchContext: LaunchContext<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>): void;
|
|
108
|
+
/**
|
|
109
|
+
* Gracefully closes the browser and makes sure
|
|
110
|
+
* there will be no lingering browser processes.
|
|
111
|
+
*
|
|
112
|
+
* Emits 'browserClosed' event.
|
|
113
|
+
*/
|
|
114
|
+
close(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Immediately kills the browser process.
|
|
117
|
+
*
|
|
118
|
+
* Emits 'browserClosed' event.
|
|
119
|
+
*/
|
|
120
|
+
kill(): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Opens new browser page.
|
|
123
|
+
* @ignore
|
|
124
|
+
*/
|
|
125
|
+
newPage(pageOptions?: NewPageOptions): Promise<NewPageResult>;
|
|
126
|
+
setCookies(page: NewPageResult, cookies: Cookie[]): Promise<void>;
|
|
127
|
+
getCookies(page: NewPageResult): Promise<Cookie[]>;
|
|
128
|
+
/**
|
|
129
|
+
* @private
|
|
130
|
+
*/
|
|
131
|
+
protected abstract _close(): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* @private
|
|
134
|
+
*/
|
|
135
|
+
protected abstract _kill(): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
protected abstract _newPage(pageOptions?: NewPageOptions): Promise<NewPageResult>;
|
|
140
|
+
/**
|
|
141
|
+
* @private
|
|
142
|
+
*/
|
|
143
|
+
protected abstract _setCookies(page: NewPageResult, cookies: Cookie[]): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* @private
|
|
146
|
+
*/
|
|
147
|
+
protected abstract _getCookies(page: NewPageResult): Promise<Cookie[]>;
|
|
148
|
+
/**
|
|
149
|
+
* @private
|
|
150
|
+
*/
|
|
151
|
+
abstract normalizeProxyOptions(proxyUrl: string | undefined, pageOptions: any): Record<string, unknown>;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=browser-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-controller.d.ts","sourceRoot":"","sources":["../../src/abstract-classes/browser-controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AA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AAC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,CAAC,GAAG,IAAI;IAS9I;;;;;OAKG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB5B;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAM3B;;;OAGG;IACG,OAAO,CAAC,WAAW,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAW7D,UAAU,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjE,UAAU,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAIxD;;OAEG;uBAGsB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhD;;OAEG;uBAGsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/C;;OAEG;uBAEsB,QAAQ,CAAC,WAAW,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAIvF;;OAEG;uBAEsB,WAAW,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3F;;OAEG;uBAEsB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAI5E;;OAEG;IAEH,QAAQ,CAAC,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,WAAW,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG1G"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BrowserController = void 0;
|
|
4
|
+
const nanoid_1 = require("nanoid");
|
|
5
|
+
const tiny_typed_emitter_1 = require("tiny-typed-emitter");
|
|
6
|
+
const timeout_1 = require("@apify/timeout");
|
|
7
|
+
const logger_1 = require("../logger");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const PROCESS_KILL_TIMEOUT_MILLIS = 5000;
|
|
10
|
+
/**
|
|
11
|
+
* The `BrowserController` serves two purposes. First, it is the base class that
|
|
12
|
+
* specialized controllers like `PuppeteerController` or `PlaywrightController`
|
|
13
|
+
* extend. Second, it defines the public interface of the specialized classes
|
|
14
|
+
* which provide only private methods. Therefore, we do not keep documentation
|
|
15
|
+
* for the specialized classes, because it's the same for all of them.
|
|
16
|
+
* @hideconstructor
|
|
17
|
+
*/
|
|
18
|
+
class BrowserController extends tiny_typed_emitter_1.TypedEmitter {
|
|
19
|
+
constructor(browserPlugin) {
|
|
20
|
+
super();
|
|
21
|
+
Object.defineProperty(this, "id", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: (0, nanoid_1.nanoid)()
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* The `BrowserPlugin` instance used to launch the browser.
|
|
29
|
+
*/
|
|
30
|
+
Object.defineProperty(this, "browserPlugin", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: void 0
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Browser representation of the underlying automation library.
|
|
38
|
+
*/
|
|
39
|
+
Object.defineProperty(this, "browser", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
writable: true,
|
|
43
|
+
value: undefined
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* The configuration the browser was launched with.
|
|
47
|
+
*/
|
|
48
|
+
Object.defineProperty(this, "launchContext", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
configurable: true,
|
|
51
|
+
writable: true,
|
|
52
|
+
value: undefined
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(this, "isActive", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
configurable: true,
|
|
57
|
+
writable: true,
|
|
58
|
+
value: false
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(this, "activePages", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
value: 0
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(this, "totalPages", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: 0
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(this, "lastPageOpenedAt", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: Date.now()
|
|
77
|
+
});
|
|
78
|
+
Object.defineProperty(this, "_activate", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: void 0
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(this, "isActivePromise", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
configurable: true,
|
|
87
|
+
writable: true,
|
|
88
|
+
value: new Promise((resolve) => {
|
|
89
|
+
this._activate = resolve;
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(this, "commitBrowser", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
configurable: true,
|
|
95
|
+
writable: true,
|
|
96
|
+
value: void 0
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(this, "hasBrowserPromise", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
configurable: true,
|
|
101
|
+
writable: true,
|
|
102
|
+
value: new Promise((resolve) => {
|
|
103
|
+
this.commitBrowser = resolve;
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
this.browserPlugin = browserPlugin;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Activates the BrowserController. If you try to open new pages before
|
|
110
|
+
* activation, the pages will get queued and will only be opened after
|
|
111
|
+
* activate is called.
|
|
112
|
+
* @ignore
|
|
113
|
+
*/
|
|
114
|
+
activate() {
|
|
115
|
+
if (!this.browser) {
|
|
116
|
+
throw new Error('Cannot activate BrowserController without an assigned browser.');
|
|
117
|
+
}
|
|
118
|
+
this._activate();
|
|
119
|
+
this.isActive = true;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @ignore
|
|
123
|
+
*/
|
|
124
|
+
assignBrowser(browser, launchContext) {
|
|
125
|
+
if (this.browser) {
|
|
126
|
+
throw new Error('BrowserController already has a browser instance assigned.');
|
|
127
|
+
}
|
|
128
|
+
this.browser = browser;
|
|
129
|
+
this.launchContext = launchContext;
|
|
130
|
+
this.commitBrowser();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Gracefully closes the browser and makes sure
|
|
134
|
+
* there will be no lingering browser processes.
|
|
135
|
+
*
|
|
136
|
+
* Emits 'browserClosed' event.
|
|
137
|
+
*/
|
|
138
|
+
async close() {
|
|
139
|
+
await this.hasBrowserPromise;
|
|
140
|
+
try {
|
|
141
|
+
await this._close();
|
|
142
|
+
// TODO: shouldn't this go in a finally instead?
|
|
143
|
+
this.isActive = false;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
logger_1.log.debug(`Could not close browser.\nCause: ${error.message}`, { id: this.id });
|
|
147
|
+
}
|
|
148
|
+
this.emit("browserClosed" /* BROWSER_CONTROLLER_EVENTS.BROWSER_CLOSED */, this);
|
|
149
|
+
setTimeout(() => {
|
|
150
|
+
this._kill().catch((err) => {
|
|
151
|
+
logger_1.log.debug(`Could not kill browser.\nCause: ${err.message}`, { id: this.id });
|
|
152
|
+
});
|
|
153
|
+
}, PROCESS_KILL_TIMEOUT_MILLIS);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Immediately kills the browser process.
|
|
157
|
+
*
|
|
158
|
+
* Emits 'browserClosed' event.
|
|
159
|
+
*/
|
|
160
|
+
async kill() {
|
|
161
|
+
await this.hasBrowserPromise;
|
|
162
|
+
await this._kill();
|
|
163
|
+
this.emit("browserClosed" /* BROWSER_CONTROLLER_EVENTS.BROWSER_CLOSED */, this);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Opens new browser page.
|
|
167
|
+
* @ignore
|
|
168
|
+
*/
|
|
169
|
+
async newPage(pageOptions) {
|
|
170
|
+
this.activePages++;
|
|
171
|
+
this.totalPages++;
|
|
172
|
+
await this.isActivePromise;
|
|
173
|
+
const page = await this._newPage(pageOptions);
|
|
174
|
+
(0, timeout_1.tryCancel)();
|
|
175
|
+
this.lastPageOpenedAt = Date.now();
|
|
176
|
+
return page;
|
|
177
|
+
}
|
|
178
|
+
async setCookies(page, cookies) {
|
|
179
|
+
return this._setCookies(page, cookies);
|
|
180
|
+
}
|
|
181
|
+
async getCookies(page) {
|
|
182
|
+
return this._getCookies(page);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* @private
|
|
186
|
+
*/
|
|
187
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
188
|
+
// eslint-disable-next-line space-before-function-paren
|
|
189
|
+
async _close() {
|
|
190
|
+
(0, utils_1.throwImplementationNeeded)('_close');
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
195
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
196
|
+
// eslint-disable-next-line space-before-function-paren
|
|
197
|
+
async _kill() {
|
|
198
|
+
(0, utils_1.throwImplementationNeeded)('_kill');
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
203
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
204
|
+
async _newPage(pageOptions) {
|
|
205
|
+
(0, utils_1.throwImplementationNeeded)('_newPage');
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* @private
|
|
209
|
+
*/
|
|
210
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
211
|
+
async _setCookies(page, cookies) {
|
|
212
|
+
(0, utils_1.throwImplementationNeeded)('_setCookies');
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* @private
|
|
216
|
+
*/
|
|
217
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
218
|
+
async _getCookies(page) {
|
|
219
|
+
(0, utils_1.throwImplementationNeeded)('_getCookies');
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* @private
|
|
223
|
+
*/
|
|
224
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
225
|
+
normalizeProxyOptions(proxyUrl, pageOptions) {
|
|
226
|
+
(0, utils_1.throwImplementationNeeded)('_normalizeProxyOptions');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
exports.BrowserController = BrowserController;
|
|
230
|
+
//# sourceMappingURL=browser-controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-controller.js","sourceRoot":"","sources":["../../src/abstract-classes/browser-controller.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,2DAAkD;AAClD,4CAA2C;AAG3C,sCAAgC;AAGhC,mCAAoD;AAEpD,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAuEzC;;;;;;;GAOG;AACH,MAAsB,iBAMpB,SAAQ,iCAA2G;IAsCjH,YAAY,aAAkG;QAC1G,KAAK,EAAE,CAAC;QAtCZ;;;;mBAAK,IAAA,eAAM,GAAE;WAAC;QAEd;;WAEG;QACH;;;;;WAAmG;QAEnG;;WAEG;QACH;;;;mBAAwB,SAAU;WAAC;QAEnC;;WAEG;QACH;;;;mBAAqG,SAAU;WAAC;QAEhH;;;;mBAAW,KAAK;WAAC;QAEjB;;;;mBAAc,CAAC;WAAC;QAEhB;;;;mBAAa,CAAC;WAAC;QAEf;;;;mBAAmB,IAAI,CAAC,GAAG,EAAE;WAAC;QAE9B;;;;;WAA+B;QAE/B;;;;mBAA0B,IAAI,OA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AA,iCAAyB,EAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,8DAA8D;IAC3C,KAAK,CAAC,QAAQ,CAAC,WAA4B;QAC1D,IAAA,iCAAyB,EAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,8DAA8D;IAC3C,KAAK,CAAC,WAAW,CAAC,IAAmB,EAAE,OAAiB;QACvE,IAAA,iCAAyB,EAAC,aAAa,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,8DAA8D;IAC3C,KAAK,CAAC,WAAW,CAAC,IAAmB;QACpD,IAAA,iCAAyB,EAAC,aAAa,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,8DAA8D;IACrD,qBAAqB,CAAC,QAA4B,EAAE,WAAgB;QACzE,IAAA,iCAAyB,EAAC,wBAAwB,CAAC,CAAC;IACxD,CAAC;CACJ;AAxLD,8CAwLC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { LaunchContext, LaunchContextOptions } from '../launch-context';
|
|
2
|
+
import { BrowserController } from './browser-controller';
|
|
3
|
+
import { UnwrapPromise } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
* The default User Agent used by `PlaywrightCrawler`, `launchPlaywright`, 'PuppeteerCrawler' and 'launchPuppeteer'
|
|
6
|
+
* when Chromium/Chrome browser is launched:
|
|
7
|
+
* - in headless mode,
|
|
8
|
+
* - without using a fingerprint,
|
|
9
|
+
* - without specifying a user agent.
|
|
10
|
+
* Last updated on 2022-05-05.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36";
|
|
13
|
+
/**
|
|
14
|
+
* Each plugin expects an instance of the object with the `.launch()` property.
|
|
15
|
+
* For Puppeteer, it is the `puppeteer` module itself, whereas for Playwright
|
|
16
|
+
* it is one of the browser types, such as `puppeteer.chromium`.
|
|
17
|
+
* `BrowserPlugin` does not include the library. You can choose any version
|
|
18
|
+
* or fork of the library. It also keeps `browser-pool` installation small.
|
|
19
|
+
*/
|
|
20
|
+
export interface CommonLibrary {
|
|
21
|
+
product?: string;
|
|
22
|
+
launch(...args: unknown[]): Promise<CommonBrowser>;
|
|
23
|
+
name?: () => string;
|
|
24
|
+
}
|
|
25
|
+
/** @internal */
|
|
26
|
+
export interface CommonBrowser {
|
|
27
|
+
newPage(...args: unknown[]): Promise<CommonPage>;
|
|
28
|
+
}
|
|
29
|
+
/** @internal */
|
|
30
|
+
export interface CommonPage {
|
|
31
|
+
close(...args: unknown[]): Promise<unknown>;
|
|
32
|
+
url(): string | Promise<string>;
|
|
33
|
+
}
|
|
34
|
+
export interface BrowserPluginOptions<LibraryOptions> {
|
|
35
|
+
/**
|
|
36
|
+
* Options that will be passed down to the automation library. E.g.
|
|
37
|
+
* `puppeteer.launch(launchOptions);`. This is a good place to set
|
|
38
|
+
* options that you want to apply as defaults. To dynamically override
|
|
39
|
+
* those options per-browser, see the `preLaunchHooks` of {@link BrowserPool}.
|
|
40
|
+
*/
|
|
41
|
+
launchOptions?: LibraryOptions;
|
|
42
|
+
/**
|
|
43
|
+
* Automation libraries configure proxies differently. This helper allows you
|
|
44
|
+
* to set a proxy URL without worrying about specific implementations.
|
|
45
|
+
* It also allows you use an authenticated proxy without extra code.
|
|
46
|
+
*/
|
|
47
|
+
proxyUrl?: string;
|
|
48
|
+
/**
|
|
49
|
+
* By default pages share the same browser context.
|
|
50
|
+
* If set to true each page uses its own context that is destroyed once the page is closed or crashes.
|
|
51
|
+
*
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
54
|
+
useIncognitoPages?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Path to a User Data Directory, which stores browser session data like cookies and local storage.
|
|
57
|
+
*/
|
|
58
|
+
userDataDir?: string;
|
|
59
|
+
}
|
|
60
|
+
export declare type CreateLaunchContextOptions<Library extends CommonLibrary, LibraryOptions = Parameters<Library['launch']>[0], LaunchResult extends CommonBrowser = UnwrapPromise<ReturnType<Library['launch']>>, NewPageOptions = Parameters<LaunchResult['newPage']>[0], NewPageResult = UnwrapPromise<ReturnType<LaunchResult['newPage']>>> = Partial<Omit<LaunchContextOptions<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>, 'browserPlugin'>>;
|
|
61
|
+
/**
|
|
62
|
+
* The `BrowserPlugin` serves two purposes. First, it is the base class that
|
|
63
|
+
* specialized controllers like `PuppeteerPlugin` or `PlaywrightPlugin` extend.
|
|
64
|
+
* Second, it allows the user to configure the automation libraries and
|
|
65
|
+
* feed them to {@link BrowserPool} for use.
|
|
66
|
+
*/
|
|
67
|
+
export declare abstract class BrowserPlugin<Library extends CommonLibrary = CommonLibrary, LibraryOptions = Parameters<Library['launch']>[0], LaunchResult extends CommonBrowser = UnwrapPromise<ReturnType<Library['launch']>>, NewPageOptions = Parameters<LaunchResult['newPage']>[0], NewPageResult = UnwrapPromise<ReturnType<LaunchResult['newPage']>>> {
|
|
68
|
+
name: string;
|
|
69
|
+
library: Library;
|
|
70
|
+
launchOptions: LibraryOptions;
|
|
71
|
+
proxyUrl?: string;
|
|
72
|
+
userDataDir?: string;
|
|
73
|
+
useIncognitoPages: boolean;
|
|
74
|
+
constructor(library: Library, options?: BrowserPluginOptions<LibraryOptions>);
|
|
75
|
+
/**
|
|
76
|
+
* Creates a `LaunchContext` with all the information needed
|
|
77
|
+
* to launch a browser. Aside from library specific launch options,
|
|
78
|
+
* it also includes internal properties used by `BrowserPool` for
|
|
79
|
+
* management of the pool and extra features.
|
|
80
|
+
*/
|
|
81
|
+
createLaunchContext(options?: CreateLaunchContextOptions<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>): LaunchContext<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>;
|
|
82
|
+
createController(): BrowserController<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Launches the browser using provided launch context.
|
|
85
|
+
*/
|
|
86
|
+
launch(launchContext?: LaunchContext<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>): Promise<LaunchResult>;
|
|
87
|
+
private _mergeArgsToHideWebdriver;
|
|
88
|
+
/**
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
protected abstract _addProxyToLaunchOptions(launchContext: LaunchContext<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>): Promise<void>;
|
|
92
|
+
protected abstract _isChromiumBasedBrowser(launchContext: LaunchContext<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
96
|
+
protected abstract _launch(launchContext: LaunchContext<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>): Promise<LaunchResult>;
|
|
97
|
+
/**
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
protected abstract _createController(): BrowserController<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=browser-plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-plugin.d.ts","sourceRoot":"","sources":["../../src/abstract-classes/browser-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,8GAA8G,CAAC;AAE9I;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC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AAC,uBAAuB,CAAC,aAAa,EAAE,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,CAAC,GAAG,OAAO;IAIvJ;;OAEG;IAEH,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,aAAa,EAAE,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;IAIrJ;;OAEG;IAGH,SAAS,CAAC,QAAQ,CAAC,iBAAiB,IAAI,iBAAiB,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,CAAC;CAGlI"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BrowserPlugin = exports.DEFAULT_USER_AGENT = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_merge_1 = tslib_1.__importDefault(require("lodash.merge"));
|
|
6
|
+
const launch_context_1 = require("../launch-context");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
/**
|
|
9
|
+
* The default User Agent used by `PlaywrightCrawler`, `launchPlaywright`, 'PuppeteerCrawler' and 'launchPuppeteer'
|
|
10
|
+
* when Chromium/Chrome browser is launched:
|
|
11
|
+
* - in headless mode,
|
|
12
|
+
* - without using a fingerprint,
|
|
13
|
+
* - without specifying a user agent.
|
|
14
|
+
* Last updated on 2022-05-05.
|
|
15
|
+
*/
|
|
16
|
+
exports.DEFAULT_USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36';
|
|
17
|
+
;
|
|
18
|
+
/**
|
|
19
|
+
* The `BrowserPlugin` serves two purposes. First, it is the base class that
|
|
20
|
+
* specialized controllers like `PuppeteerPlugin` or `PlaywrightPlugin` extend.
|
|
21
|
+
* Second, it allows the user to configure the automation libraries and
|
|
22
|
+
* feed them to {@link BrowserPool} for use.
|
|
23
|
+
*/
|
|
24
|
+
class BrowserPlugin {
|
|
25
|
+
constructor(library, options = {}) {
|
|
26
|
+
Object.defineProperty(this, "name", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: this.constructor.name
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(this, "library", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: void 0
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(this, "launchOptions", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true,
|
|
42
|
+
value: void 0
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(this, "proxyUrl", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
writable: true,
|
|
48
|
+
value: void 0
|
|
49
|
+
});
|
|
50
|
+
Object.defineProperty(this, "userDataDir", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
configurable: true,
|
|
53
|
+
writable: true,
|
|
54
|
+
value: void 0
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(this, "useIncognitoPages", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
configurable: true,
|
|
59
|
+
writable: true,
|
|
60
|
+
value: void 0
|
|
61
|
+
});
|
|
62
|
+
const { launchOptions = {}, proxyUrl, userDataDir, useIncognitoPages = false, } = options;
|
|
63
|
+
this.library = library;
|
|
64
|
+
this.launchOptions = launchOptions;
|
|
65
|
+
this.proxyUrl = proxyUrl && new URL(proxyUrl).href;
|
|
66
|
+
this.userDataDir = userDataDir;
|
|
67
|
+
this.useIncognitoPages = useIncognitoPages;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates a `LaunchContext` with all the information needed
|
|
71
|
+
* to launch a browser. Aside from library specific launch options,
|
|
72
|
+
* it also includes internal properties used by `BrowserPool` for
|
|
73
|
+
* management of the pool and extra features.
|
|
74
|
+
*/
|
|
75
|
+
createLaunchContext(options = {}) {
|
|
76
|
+
const { id, launchOptions = {}, proxyUrl = this.proxyUrl, useIncognitoPages = this.useIncognitoPages, userDataDir = this.userDataDir, } = options;
|
|
77
|
+
return new launch_context_1.LaunchContext({
|
|
78
|
+
id,
|
|
79
|
+
launchOptions: (0, lodash_merge_1.default)({}, this.launchOptions, launchOptions),
|
|
80
|
+
browserPlugin: this,
|
|
81
|
+
proxyUrl,
|
|
82
|
+
useIncognitoPages,
|
|
83
|
+
userDataDir,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
createController() {
|
|
87
|
+
return this._createController();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Launches the browser using provided launch context.
|
|
91
|
+
*/
|
|
92
|
+
async launch(launchContext = this.createLaunchContext()) {
|
|
93
|
+
const { proxyUrl, launchOptions } = launchContext;
|
|
94
|
+
if (proxyUrl) {
|
|
95
|
+
await this._addProxyToLaunchOptions(launchContext);
|
|
96
|
+
}
|
|
97
|
+
if (this._isChromiumBasedBrowser(launchContext)) {
|
|
98
|
+
// This will set the args for chromium based browsers to hide the webdriver.
|
|
99
|
+
launchOptions.args = this._mergeArgsToHideWebdriver(launchOptions.args);
|
|
100
|
+
// When User-Agent is not set, and we're using Chromium in headless mode,
|
|
101
|
+
// it is better to use DEFAULT_USER_AGENT to reduce chance of detection,
|
|
102
|
+
// as otherwise 'HeadlessChrome' is present in User-Agent string.
|
|
103
|
+
const userAgent = launchOptions.args.find((arg) => arg.startsWith('--user-agent'));
|
|
104
|
+
if (launchOptions.headless && !launchContext.fingerprint && !userAgent) {
|
|
105
|
+
launchOptions.args.push(`--user-agent=${exports.DEFAULT_USER_AGENT}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return this._launch(launchContext);
|
|
109
|
+
}
|
|
110
|
+
_mergeArgsToHideWebdriver(originalArgs) {
|
|
111
|
+
if (!originalArgs?.length) {
|
|
112
|
+
return ['--disable-blink-features=AutomationControlled'];
|
|
113
|
+
}
|
|
114
|
+
const argumentIndex = originalArgs.findIndex((arg) => arg.startsWith('--disable-blink-features='));
|
|
115
|
+
if (argumentIndex !== -1) {
|
|
116
|
+
originalArgs[argumentIndex] += ',AutomationControlled';
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
originalArgs.push('--disable-blink-features=AutomationControlled');
|
|
120
|
+
}
|
|
121
|
+
return originalArgs;
|
|
122
|
+
}
|
|
123
|
+
;
|
|
124
|
+
/**
|
|
125
|
+
* @private
|
|
126
|
+
*/
|
|
127
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
128
|
+
// eslint-disable-next-line max-len
|
|
129
|
+
_addProxyToLaunchOptions(launchContext) {
|
|
130
|
+
(0, utils_1.throwImplementationNeeded)('_addProxyToLaunchOptions');
|
|
131
|
+
}
|
|
132
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
133
|
+
// eslint-disable-next-line space-before-function-paren, @typescript-eslint/no-unused-vars, max-len
|
|
134
|
+
_isChromiumBasedBrowser(launchContext) {
|
|
135
|
+
(0, utils_1.throwImplementationNeeded)('_isChromiumBasedBrowser');
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
141
|
+
_launch(launchContext) {
|
|
142
|
+
(0, utils_1.throwImplementationNeeded)('_launch');
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @private
|
|
146
|
+
*/
|
|
147
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
148
|
+
// eslint-disable-next-line space-before-function-paren
|
|
149
|
+
_createController() {
|
|
150
|
+
(0, utils_1.throwImplementationNeeded)('_createController');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.BrowserPlugin = BrowserPlugin;
|
|
154
|
+
//# sourceMappingURL=browser-plugin.js.map
|