@crawlee/browser-pool 3.0.0-alpha.12 → 3.0.0-alpha.13
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/abstract-classes/browser-controller.d.ts +153 -0
- package/abstract-classes/browser-controller.d.ts.map +1 -0
- package/abstract-classes/browser-controller.js +234 -0
- package/abstract-classes/browser-controller.js.map +1 -0
- package/abstract-classes/browser-plugin.d.ts +91 -0
- package/abstract-classes/browser-plugin.d.ts.map +1 -0
- package/abstract-classes/browser-plugin.js +116 -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 +89 -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 +5 -0
- package/fingerprinting/utils.d.ts.map +1 -0
- package/fingerprinting/utils.js +61 -0
- package/fingerprinting/utils.js.map +1 -0
- package/index.d.ts +35 -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 +1 -4
- package/playwright/browser.d.ts +26 -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 +11 -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 +11 -0
- package/playwright/playwright-plugin.d.ts.map +1 -0
- package/playwright/playwright-plugin.js +85 -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 +19 -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 +11 -0
- package/puppeteer/puppeteer-plugin.d.ts.map +1 -0
- package/puppeteer/puppeteer-plugin.js +137 -0
- package/puppeteer/puppeteer-plugin.js.map +1 -0
- package/puppeteer/puppeteer-proxy-per-page.d.ts +25 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/utils.d.ts +6 -0
- package/utils.d.ts.map +1 -0
- package/utils.js +7 -0
- package/utils.js.map +1 -0
|
@@ -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;AAK/E,MAAM,WAAW,uBAAuB,CACpC,OAAO,SAAS,aAAa,EAC7B,cAAc,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EACjD,YAAY,SAAS,aAAa,GAAG,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EACjF,cAAc,GAAG,UAAU,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EACvD,aAAa,GAAG,aAAa,CAAC,UAAU,CAAC,YAAY,CAAC,SAAS,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,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;uBAGsB,QAAQ,CAAC,WAAW,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAIvF;;OAEG;uBAGsB,WAAW,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI3F;;OAEG;uBAGsB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAI5E;;OAEG;IAGH,QAAQ,CAAC,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,WAAW,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAG1G"}
|
|
@@ -0,0 +1,234 @@
|
|
|
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_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_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
|
+
// eslint-disable-next-line space-before-function-paren, @typescript-eslint/no-unused-vars
|
|
205
|
+
async _newPage(pageOptions) {
|
|
206
|
+
(0, utils_1.throwImplementationNeeded)('_newPage');
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
211
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
212
|
+
// eslint-disable-next-line space-before-function-paren, @typescript-eslint/no-unused-vars
|
|
213
|
+
async _setCookies(page, cookies) {
|
|
214
|
+
(0, utils_1.throwImplementationNeeded)('_setCookies');
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* @private
|
|
218
|
+
*/
|
|
219
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
220
|
+
// eslint-disable-next-line space-before-function-paren, @typescript-eslint/no-unused-vars
|
|
221
|
+
async _getCookies(page) {
|
|
222
|
+
(0, utils_1.throwImplementationNeeded)('_getCookies');
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* @private
|
|
226
|
+
*/
|
|
227
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
228
|
+
// eslint-disable-next-line space-before-function-paren, @typescript-eslint/no-unused-vars
|
|
229
|
+
normalizeProxyOptions(proxyUrl, pageOptions) {
|
|
230
|
+
(0, utils_1.throwImplementationNeeded)('_normalizeProxyOptions');
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.BrowserController = BrowserController;
|
|
234
|
+
//# 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,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBACpD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC;YAC7B,CAAC,CAAC;WAAC;QAEH;;;;;WAAmC;QAEnC;;;;mBAA4B,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;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AAC;IAED;;OAEG;IACH,8DAA8D;IAC9D,0FAA0F;IACvE,KAAK,CAAC,WAAW,CAAC,IAAmB,EAAE,OAAiB;QACvE,IAAA,iCAAyB,EAAC,aAAa,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,8DAA8D;IAC9D,0FAA0F;IACvE,KAAK,CAAC,WAAW,CAAC,IAAmB;QACpD,IAAA,iCAAyB,EAAC,aAAa,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,8DAA8D;IAC9D,0FAA0F;IACjF,qBAAqB,CAAC,QAA4B,EAAE,WAAgB;QACzE,IAAA,iCAAyB,EAAC,wBAAwB,CAAC,CAAC;IACxD,CAAC;CACJ;AA5LD,8CA4LC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { LaunchContext, LaunchContextOptions } from '../launch-context';
|
|
2
|
+
import { BrowserController } from './browser-controller';
|
|
3
|
+
import { UnwrapPromise } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
* Each plugin expects an instance of the object with the `.launch()` property.
|
|
6
|
+
* For Puppeteer, it is the `puppeteer` module itself, whereas for Playwright
|
|
7
|
+
* it is one of the browser types, such as `puppeteer.chromium`.
|
|
8
|
+
* `BrowserPlugin` does not include the library. You can choose any version
|
|
9
|
+
* or fork of the library. It also keeps `browser-pool` installation small.
|
|
10
|
+
*/
|
|
11
|
+
export interface CommonLibrary {
|
|
12
|
+
product?: string;
|
|
13
|
+
launch(...args: unknown[]): Promise<CommonBrowser>;
|
|
14
|
+
name?: () => string;
|
|
15
|
+
}
|
|
16
|
+
/** @internal */
|
|
17
|
+
export interface CommonBrowser {
|
|
18
|
+
newPage(...args: unknown[]): Promise<CommonPage>;
|
|
19
|
+
}
|
|
20
|
+
/** @internal */
|
|
21
|
+
export interface CommonPage {
|
|
22
|
+
close(...args: unknown[]): Promise<unknown>;
|
|
23
|
+
url(): string | Promise<string>;
|
|
24
|
+
}
|
|
25
|
+
export interface BrowserPluginOptions<LibraryOptions> {
|
|
26
|
+
/**
|
|
27
|
+
* Options that will be passed down to the automation library. E.g.
|
|
28
|
+
* `puppeteer.launch(launchOptions);`. This is a good place to set
|
|
29
|
+
* options that you want to apply as defaults. To dynamically override
|
|
30
|
+
* those options per-browser, see the `preLaunchHooks` of {@link BrowserPool}.
|
|
31
|
+
*/
|
|
32
|
+
launchOptions?: LibraryOptions;
|
|
33
|
+
/**
|
|
34
|
+
* Automation libraries configure proxies differently. This helper allows you
|
|
35
|
+
* to set a proxy URL without worrying about specific implementations.
|
|
36
|
+
* It also allows you use an authenticated proxy without extra code.
|
|
37
|
+
*/
|
|
38
|
+
proxyUrl?: string;
|
|
39
|
+
/**
|
|
40
|
+
* By default pages share the same browser context.
|
|
41
|
+
* If set to true each page uses its own context that is destroyed once the page is closed or crashes.
|
|
42
|
+
*
|
|
43
|
+
* @default false
|
|
44
|
+
*/
|
|
45
|
+
useIncognitoPages?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Path to a User Data Directory, which stores browser session data like cookies and local storage.
|
|
48
|
+
*/
|
|
49
|
+
userDataDir?: string;
|
|
50
|
+
}
|
|
51
|
+
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'>>;
|
|
52
|
+
/**
|
|
53
|
+
* The `BrowserPlugin` serves two purposes. First, it is the base class that
|
|
54
|
+
* specialized controllers like `PuppeteerPlugin` or `PlaywrightPlugin` extend.
|
|
55
|
+
* Second, it allows the user to configure the automation libraries and
|
|
56
|
+
* feed them to {@link BrowserPool} for use.
|
|
57
|
+
*/
|
|
58
|
+
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']>>> {
|
|
59
|
+
name: string;
|
|
60
|
+
library: Library;
|
|
61
|
+
launchOptions: LibraryOptions;
|
|
62
|
+
proxyUrl?: string;
|
|
63
|
+
userDataDir?: string;
|
|
64
|
+
useIncognitoPages: boolean;
|
|
65
|
+
constructor(library: Library, options?: BrowserPluginOptions<LibraryOptions>);
|
|
66
|
+
/**
|
|
67
|
+
* Creates a `LaunchContext` with all the information needed
|
|
68
|
+
* to launch a browser. Aside from library specific launch options,
|
|
69
|
+
* it also includes internal properties used by `BrowserPool` for
|
|
70
|
+
* management of the pool and extra features.
|
|
71
|
+
*/
|
|
72
|
+
createLaunchContext(options?: CreateLaunchContextOptions<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>): LaunchContext<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>;
|
|
73
|
+
createController(): BrowserController<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Launches the browser using provided launch context.
|
|
76
|
+
*/
|
|
77
|
+
launch(launchContext?: LaunchContext<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>): Promise<LaunchResult>;
|
|
78
|
+
/**
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
protected abstract _addProxyToLaunchOptions(launchContext: LaunchContext<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
protected abstract _launch(launchContext: LaunchContext<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>): Promise<LaunchResult>;
|
|
86
|
+
/**
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
protected abstract _createController(): BrowserController<Library, LibraryOptions, LaunchResult, NewPageOptions, NewPageResult>;
|
|
90
|
+
}
|
|
91
|
+
//# 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;;;;;;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;IACnD,IAAI,CAAC,EAAE,MAAM,MAAM,CAAC;CACvB;AAED,gBAAgB;AAChB,MAAM,WAAW,aAAa;IAC1B,OAAO,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACpD;AAED,gBAAgB;AAChB,MAAM,WAAW,UAAU;IACvB,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5C,GAAG,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,oBAAoB,CAAC,cAAc;IAChD;;;;;OAKG;IACH,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,oBAAY,0BAA0B,CAClC,OAAO,SAAS,aAAa,EAC7B,cAAc,GAAG,UA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aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,CAAC;IAmBtF,gBAAgB,IAAI,iBAAiB,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,CAAC;IAI3G;;OAEG;IACG,MAAM,CACR,aAAa,GAAE,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,CAA8B,GAChI,OAAO,CAAC,YAAY,CAAC;IAUxB;;OAEG;IAGH,SAAS,CAAC,QAAQ,CAAC,wBAAwB,CAAC,aAAa,EAAE,aAAa,CAAC,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9J;;OAEG;IAGH,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,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BrowserPlugin = 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
|
+
/**
|
|
10
|
+
* The `BrowserPlugin` serves two purposes. First, it is the base class that
|
|
11
|
+
* specialized controllers like `PuppeteerPlugin` or `PlaywrightPlugin` extend.
|
|
12
|
+
* Second, it allows the user to configure the automation libraries and
|
|
13
|
+
* feed them to {@link BrowserPool} for use.
|
|
14
|
+
*/
|
|
15
|
+
class BrowserPlugin {
|
|
16
|
+
constructor(library, options = {}) {
|
|
17
|
+
Object.defineProperty(this, "name", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: this.constructor.name
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "library", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "launchOptions", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "proxyUrl", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(this, "userDataDir", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
configurable: true,
|
|
44
|
+
writable: true,
|
|
45
|
+
value: void 0
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(this, "useIncognitoPages", {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
configurable: true,
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
const { launchOptions = {}, proxyUrl, userDataDir, useIncognitoPages = false, } = options;
|
|
54
|
+
this.library = library;
|
|
55
|
+
this.launchOptions = launchOptions;
|
|
56
|
+
this.proxyUrl = proxyUrl && new URL(proxyUrl).href;
|
|
57
|
+
this.userDataDir = userDataDir;
|
|
58
|
+
this.useIncognitoPages = useIncognitoPages;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a `LaunchContext` with all the information needed
|
|
62
|
+
* to launch a browser. Aside from library specific launch options,
|
|
63
|
+
* it also includes internal properties used by `BrowserPool` for
|
|
64
|
+
* management of the pool and extra features.
|
|
65
|
+
*/
|
|
66
|
+
createLaunchContext(options = {}) {
|
|
67
|
+
const { id, launchOptions = {}, proxyUrl = this.proxyUrl, useIncognitoPages = this.useIncognitoPages, userDataDir = this.userDataDir, } = options;
|
|
68
|
+
return new launch_context_1.LaunchContext({
|
|
69
|
+
id,
|
|
70
|
+
launchOptions: (0, lodash_merge_1.default)({}, this.launchOptions, launchOptions),
|
|
71
|
+
browserPlugin: this,
|
|
72
|
+
proxyUrl,
|
|
73
|
+
useIncognitoPages,
|
|
74
|
+
userDataDir,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
createController() {
|
|
78
|
+
return this._createController();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Launches the browser using provided launch context.
|
|
82
|
+
*/
|
|
83
|
+
async launch(launchContext = this.createLaunchContext()) {
|
|
84
|
+
const { proxyUrl } = launchContext;
|
|
85
|
+
if (proxyUrl) {
|
|
86
|
+
await this._addProxyToLaunchOptions(launchContext);
|
|
87
|
+
}
|
|
88
|
+
return this._launch(launchContext);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
94
|
+
// eslint-disable-next-line space-before-function-paren, @typescript-eslint/no-unused-vars, max-len
|
|
95
|
+
_addProxyToLaunchOptions(launchContext) {
|
|
96
|
+
(0, utils_1.throwImplementationNeeded)('_addProxyToLaunchOptions');
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
101
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
102
|
+
// eslint-disable-next-line space-before-function-paren, @typescript-eslint/no-unused-vars, max-len
|
|
103
|
+
_launch(launchContext) {
|
|
104
|
+
(0, utils_1.throwImplementationNeeded)('_launch');
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
109
|
+
// @ts-expect-error Give runtime error as well as compile time
|
|
110
|
+
// eslint-disable-next-line space-before-function-paren
|
|
111
|
+
_createController() {
|
|
112
|
+
(0, utils_1.throwImplementationNeeded)('_createController');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.BrowserPlugin = BrowserPlugin;
|
|
116
|
+
//# sourceMappingURL=browser-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-plugin.js","sourceRoot":"","sources":["../../src/abstract-classes/browser-plugin.ts"],"names":[],"mappings":";;;;AAAA,wEAAiC;AACjC,sDAAwE;AAExE,mCAAoD;AAoDnD,CAAC;AAUF;;;;;GAKG;AACH,MAAsB,aAAa;IAmB/B,YAAY,OAAgB,EAAE,UAAgD,EAAE;QAZhF;;;;mBAAO,IAAI,CAAC,WAAW,CAAC,IAAI;WAAC;QAE7B;;;;;WAAiB;QAEjB;;;;;WAA8B;QAE9B;;;;;WAAkB;QAElB;;;;;WAAqB;QAErB;;;;;WAA2B;QAGvB,MAAM,EACF,aAAa,GAAG,EAAoB,EACpC,QAAQ,EACR,WAAW,EACX,iBAAiB,GAAG,KAAK,GAC5B,GAAG,OAAO,CAAC;QAEZ,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC;QACnD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC/C,CAAC;IAED;;;;;OAKG;IACH,mBAAmB,CACf,UAA4G,EAAE;QAE9G,MAAM,EACF,EAAE,EACF,aAAa,GAAG,EAAE,EAClB,QAAQ,GAAG,IAAI,CAAC,QAAQ,EACxB,iBAAiB,GAAG,IAAI,CAAC,iBAA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1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwImplementationNeeded = void 0;
|
|
4
|
+
function throwImplementationNeeded(methodName) {
|
|
5
|
+
throw new Error(`You need to implement method ${methodName}.`);
|
|
6
|
+
}
|
|
7
|
+
exports.throwImplementationNeeded = throwImplementationNeeded;
|
|
8
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/abstract-classes/utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,yBAAyB,CAAC,UAAkB;IACxD,MAAM,IAAI,KAAK,CAAC,gCAAgC,UAAU,GAAG,CAAC,CAAC;AACnE,CAAC;AAFD,8DAEC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare type PromiseVoid = () => Promise<void>;
|
|
2
|
+
export declare const anonymizeProxySugar: (proxyUrl?: string | undefined, username?: string | undefined, password?: string | undefined) => Promise<[string | undefined, PromiseVoid]>;
|
|
3
|
+
export {};
|
|
4
|
+
//# sourceMappingURL=anonymize-proxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anonymize-proxy.d.ts","sourceRoot":"","sources":["../src/anonymize-proxy.ts"],"names":[],"mappings":"AAEA,aAAK,WAAW,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAEvC,eAAO,MAAM,mBAAmB,mGAI7B,QAAQ,CAAC,MAAM,GAAG,SAAS,EAAE,WAAW,CAAC,CAgC3C,CAAC"}
|