puppeteer-pro 1.9.10 → 2.0.0

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.
Files changed (34) hide show
  1. package/README.md +85 -84
  2. package/index.d.ts +29 -19
  3. package/index.d.ts.map +1 -1
  4. package/index.js +79 -76
  5. package/index.js.map +1 -1
  6. package/package.json +5 -5
  7. package/plugins/anonymize.user.agent/index.d.ts +2 -2
  8. package/plugins/anonymize.user.agent/index.d.ts.map +1 -1
  9. package/plugins/anonymize.user.agent/index.js +2 -2
  10. package/plugins/anonymize.user.agent/index.js.map +1 -1
  11. package/plugins/avoid.detection/index.d.ts +2 -2
  12. package/plugins/avoid.detection/index.d.ts.map +1 -1
  13. package/plugins/avoid.detection/index.js +4 -4
  14. package/plugins/avoid.detection/index.js.map +1 -1
  15. package/plugins/block.resources/index.d.ts +1 -1
  16. package/plugins/block.resources/index.d.ts.map +1 -1
  17. package/plugins/block.resources/index.js +2 -2
  18. package/plugins/block.resources/index.js.map +1 -1
  19. package/plugins/disable.dialogs/index.d.ts +1 -1
  20. package/plugins/disable.dialogs/index.d.ts.map +1 -1
  21. package/plugins/disable.dialogs/index.js +2 -2
  22. package/plugins/disable.dialogs/index.js.map +1 -1
  23. package/plugins/manage.cookies/index.d.ts +1 -1
  24. package/plugins/manage.cookies/index.d.ts.map +1 -1
  25. package/plugins/manage.cookies/index.js +19 -12
  26. package/plugins/manage.cookies/index.js.map +1 -1
  27. package/plugins/manage.localstorage/index.d.ts +1 -1
  28. package/plugins/manage.localstorage/index.d.ts.map +1 -1
  29. package/plugins/manage.localstorage/index.js +11 -7
  30. package/plugins/manage.localstorage/index.js.map +1 -1
  31. package/plugins/solve.recaptcha/index.d.ts +2 -2
  32. package/plugins/solve.recaptcha/index.d.ts.map +1 -1
  33. package/plugins/solve.recaptcha/index.js +4 -4
  34. package/plugins/solve.recaptcha/index.js.map +1 -1
package/README.md CHANGED
@@ -1,84 +1,85 @@
1
- # Puppeteer-Pro
2
-
3
- A simple [`puppeteer`](https://github.com/puppeteer/puppeteer) wrapper to enable useful plugins with ease
4
-
5
- ## Installation
6
-
7
- Requires node v10 and higher
8
-
9
- ```bash
10
- npm install puppeteer-pro
11
- ```
12
-
13
- ## Quickstart
14
-
15
- Puppeteer-Pro can do all the same things as [`puppeteer`](https://github.com/puppeteer/puppeteer), just now with plugins!
16
-
17
- ```js
18
- // Puppeteer-Pro is a drop-in replacement for puppeteer
19
- const PuppeteerPro = require('puppeteer-pro');
20
-
21
- // Enable the 'avoidDetection' plugin to prevent headless detection
22
- PuppeteerPro.avoidDetection();
23
-
24
- // Enable the 'solveRecaptchas' plugin to solve Google's recaptchas (remember to provide a wit.api API access token)
25
- const solver = PuppeteerPro.solveRecaptchas('WIT_AI_ACCESS_TOKEN');
26
-
27
- (async () => {
28
- const browser = await PuppeteerPro.launch();
29
- const page = await browser.newPage();
30
-
31
- console.log('Testing the 🐱‍👤 avoidDetection 🐱‍👤 plugin..')
32
- await page.goto('https://arh.antoinevastel.com/bots/areyouheadless');
33
- await page.screenshot({ path: 'are-you-headless.png' });
34
-
35
- console.log('Testing the recaptcha solver..')
36
- await page.goto('https://recaptcha-demo.appspot.com/recaptcha-v2-checkbox.php');
37
- await solver.waitForCaptcha(page); // Captcha script is deferred, so will load after page.goto completes
38
- await solver.solveRecaptcha(page);
39
- await page.screenshot({ path: 'is-recaptcha-solved.png' });
40
-
41
- await browser.close();
42
- })();
43
- ```
44
-
45
- ## Passive Improvements
46
-
47
- - There can be multiple request interception handlers for the same request. In such cases, the resulting response will prioritize [`respond`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#httprequestrespondresponse), followed by [`abort`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#httprequestaborterrorcode), followed by [`continue`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#httprequestcontinueoverrides). For example:
48
- - If amongst 5 handlers, respond is called 1 time, abort is called 2 times and continue is called 2 times, the result will be `respond`. This will occur after the first respond is called and not when all handlers are finished.
49
- - If amongst 5 handlers, abort is called 1 time and continue is called 4 times, the result will be `abort`. This will occur after all handlers are finished.
50
- - If amongst 5 handlers, all handlers call continue, the result will be `continue`. This will occur after all handlers are finished.
51
-
52
- ## Optional Built-in Plugins
53
-
54
- ### Anonymize User Agent
55
-
56
- - Anonymize the user-agent across all pages
57
-
58
- ### Avoid Detection
59
-
60
- - Multiple techniques to combat headless browser detection
61
-
62
- ### Block Resources
63
-
64
- - Block any [resource type](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#httprequestresourcetype) from loading
65
- - Can be used to speed up loading websites by blocking style sheets and images
66
-
67
- ### Disable Dialogs
68
-
69
- - Block dialogs from popping up and stopping execution
70
-
71
- ### Manage Cookies
72
-
73
- - Save and load cookies across sessions
74
- - Supports multiple profiles and switching between profiles
75
-
76
- ### Manage Local Storage
77
-
78
- - Save and load local storage across sessions
79
- - Supports multiple profiles and switching between profiles
80
-
81
- ### Solve Recaptcha
82
-
83
- - Solve Google's reCAPTCHA v2
84
- - Requires a FREE [wit.ai](https://wit.ai/apps) access token
1
+ # Puppeteer-Pro
2
+
3
+ A simple [`puppeteer`](https://github.com/puppeteer/puppeteer) wrapper to enable useful plugins with ease
4
+
5
+ ## Installation
6
+
7
+ Requires node v10 and higher
8
+
9
+ ```bash
10
+ npm install puppeteer-pro
11
+ ```
12
+
13
+ ## Quickstart
14
+
15
+ Puppeteer-Pro can do all the same things as [`puppeteer`](https://github.com/puppeteer/puppeteer), just now with plugins!
16
+
17
+ ```js
18
+ // Puppeteer-Pro is a drop-in replacement for puppeteer
19
+ const PuppeteerPro = require('puppeteer-pro');
20
+
21
+ (async () => {
22
+ const browser = await PuppeteerPro.launch();
23
+
24
+ // Enable the 'avoidDetection' plugin to prevent headless detection
25
+ browser.avoidDetection();
26
+
27
+ // Enable the 'solveRecaptchas' plugin to solve Google's recaptchas (remember to provide a wit.api API access token)
28
+ const solver = await browser.solveRecaptchas('WIT_AI_ACCESS_TOKEN');
29
+
30
+ const page = await browser.newPage();
31
+
32
+ console.log('Testing the 🐱‍👤 avoidDetection 🐱‍👤 plugin..')
33
+ await page.goto('https://arh.antoinevastel.com/bots/areyouheadless');
34
+ await page.screenshot({ path: 'are-you-headless.png' });
35
+
36
+ console.log('Testing the recaptcha solver..')
37
+ await page.goto('https://recaptcha-demo.appspot.com/recaptcha-v2-checkbox.php');
38
+ await solver.waitForCaptcha(page); // Captcha script is deferred, so will load after page.goto completes
39
+ await solver.solveRecaptcha(page);
40
+ await page.screenshot({ path: 'is-recaptcha-solved.png' });
41
+
42
+ await browser.close();
43
+ })();
44
+ ```
45
+
46
+ ## Passive Improvements
47
+
48
+ - There can be multiple request interception handlers for the same request. In such cases, the resulting response will prioritize [`respond`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#httprequestrespondresponse), followed by [`abort`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#httprequestaborterrorcode), followed by [`continue`](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#httprequestcontinueoverrides). For example:
49
+ - If amongst 5 handlers, respond is called 1 time, abort is called 2 times and continue is called 2 times, the result will be `respond`. This will occur after the first respond is called and not when all handlers are finished.
50
+ - If amongst 5 handlers, abort is called 1 time and continue is called 4 times, the result will be `abort`. This will occur after all handlers are finished.
51
+ - If amongst 5 handlers, all handlers call continue, the result will be `continue`. This will occur after all handlers are finished.
52
+
53
+ ## Optional Built-in Plugins
54
+
55
+ ### Anonymize User Agent
56
+
57
+ - Anonymize the user-agent across all pages
58
+
59
+ ### Avoid Detection
60
+
61
+ - Multiple techniques to combat headless browser detection
62
+
63
+ ### Block Resources
64
+
65
+ - Block any [resource type](https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#httprequestresourcetype) from loading
66
+ - Can be used to speed up loading websites by blocking style sheets and images
67
+
68
+ ### Disable Dialogs
69
+
70
+ - Block dialogs from popping up and stopping execution
71
+
72
+ ### Manage Cookies
73
+
74
+ - Save and load cookies across sessions
75
+ - Supports multiple profiles and switching between profiles
76
+
77
+ ### Manage Local Storage
78
+
79
+ - Save and load local storage across sessions
80
+ - Supports multiple profiles and switching between profiles
81
+
82
+ ### Solve Recaptcha
83
+
84
+ - Solve Google's reCAPTCHA v2
85
+ - Requires a FREE [wit.ai](https://wit.ai/apps) access token
package/index.d.ts CHANGED
@@ -1,9 +1,14 @@
1
+ import * as events from 'events';
1
2
  import * as Puppeteer from 'puppeteer';
2
- export declare function connect(options?: Puppeteer.ConnectOptions): Promise<Puppeteer.Browser>;
3
- /** The method launches a browser instance with given arguments. The browser will be closed when the parent node.js process is closed. */
4
- export declare function launch(options?: Puppeteer.LaunchOptions & Puppeteer.ConnectOptions): Promise<Puppeteer.Browser>;
3
+ export declare function connect(options?: Puppeteer.ConnectOptions): Promise<Browser>;
4
+ export declare function launch(options?: Puppeteer.LaunchOptions & Puppeteer.ConnectOptions): Promise<Browser>;
5
+ export interface Browser extends Puppeteer.Browser, Pluginable {
6
+ createBrowserContext(options?: Puppeteer.BrowserContextOptions): Promise<BrowserContext>;
7
+ }
8
+ export interface BrowserContext extends Puppeteer.BrowserContext, Pluginable {
9
+ }
5
10
  export declare class Plugin {
6
- protected browser: Puppeteer.Browser | null;
11
+ protected browser: Browser | BrowserContext | null;
7
12
  private initialized;
8
13
  private startCounter;
9
14
  protected dependencies: Plugin[];
@@ -11,8 +16,8 @@ export declare class Plugin {
11
16
  get isInitialized(): boolean;
12
17
  get isStopped(): boolean;
13
18
  addDependency(plugin: Plugin): Promise<void>;
14
- init(browser: Puppeteer.Browser): Promise<void>;
15
- protected afterLaunch(_browser: Puppeteer.Browser): Promise<void>;
19
+ init(browser: Browser | BrowserContext): Promise<void>;
20
+ protected afterLaunch(_browser: Browser | BrowserContext): Promise<void>;
16
21
  protected onClose(): Promise<void>;
17
22
  protected onTargetCreated(target: Puppeteer.Target): Promise<void>;
18
23
  protected onPageCreated(_page: Puppeteer.Page): Promise<void>;
@@ -28,24 +33,29 @@ export declare class Plugin {
28
33
  protected afterStop(): Promise<void>;
29
34
  protected getFirstPage(): Promise<Puppeteer.Page | null>;
30
35
  }
31
- export declare function addPlugin(plugin: Plugin): void;
32
- export declare function clearPlugins(): Promise<void>;
33
- import { AnonymizeUserAgentPlugin } from './plugins/anonymize.user.agent/index';
34
- export declare function anonymizeUserAgent(): AnonymizeUserAgentPlugin;
36
+ interface Pluginable {
37
+ plugins: Plugin[];
38
+ browserEvents: events.EventEmitter;
39
+ interceptions: number;
40
+ addPlugin: (plugin: Plugin) => Promise<void>;
41
+ clearPlugins: () => void;
42
+ anonymizeUserAgent: () => Promise<AnonymizeUserAgentPlugin>;
43
+ avoidDetection: () => Promise<AvoidDetectionPlugin>;
44
+ blockResources: (...resources: Resource[]) => Promise<BlockResourcesPlugin>;
45
+ disableDialogs: (logMessages?: boolean) => Promise<DisableDialogsPlugin>;
46
+ manageCookies: (opts: ManageCookiesOption) => Promise<ManageCookiesPlugin>;
47
+ manageLocalStorage: (opts: ManageLocalStorageOption) => Promise<ManageLocalStoragePlugin>;
48
+ solveRecaptchas: (accessToken: string) => Promise<SolveRecaptchaPlugin>;
49
+ }
50
+ interface Dialog extends Puppeteer.Dialog {
51
+ handled: boolean;
52
+ }
53
+ import { AnonymizeUserAgentPlugin } from './plugins/anonymize.user.agent';
35
54
  import { AvoidDetectionPlugin } from './plugins/avoid.detection';
36
- export declare function avoidDetection(): AvoidDetectionPlugin;
37
55
  import { BlockResourcesPlugin, Resource } from './plugins/block.resources';
38
- export declare function blockResources(...resources: Resource[]): BlockResourcesPlugin;
39
56
  import { DisableDialogsPlugin } from './plugins/disable.dialogs';
40
- export declare function disableDialogs(logMessages?: boolean): DisableDialogsPlugin;
41
57
  import { ManageCookiesOption, ManageCookiesPlugin } from './plugins/manage.cookies';
42
- export declare function manageCookies(opts: ManageCookiesOption): ManageCookiesPlugin;
43
58
  import { ManageLocalStorageOption, ManageLocalStoragePlugin } from './plugins/manage.localstorage';
44
- export declare function manageLocalStorage(opts: ManageLocalStorageOption): ManageLocalStoragePlugin;
45
59
  import { SolveRecaptchaPlugin } from './plugins/solve.recaptcha';
46
- export declare function solveRecaptchas(accessToken: string): SolveRecaptchaPlugin;
47
- interface Dialog extends Puppeteer.Dialog {
48
- handled: boolean;
49
- }
50
60
  export {};
51
61
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAIvC,wBAAsB,OAAO,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAc5F;AAED,yIAAyI;AACzI,wBAAsB,MAAM,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,aAAa,GAAG,SAAS,CAAC,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAiBrH;AAID,qBAAa,MAAM;IACjB,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,OAAO,GAAG,IAAI,CAAQ;IACnD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,YAAY,CAAK;IACzB,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,CAAM;IACtC,SAAS,CAAC,oBAAoB,UAAS;IAEvC,IAAI,aAAa,YAA+B;IAChD,IAAI,SAAS,YAAsC;IAE7C,aAAa,CAAC,MAAM,EAAE,MAAM;IAI5B,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,OAAO;cA6BrB,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC,OAAO;cACvC,OAAO;cAEP,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM;cAqExC,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,IAAI;cAEnC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,WAAW;cAQxC,cAAc,CAAC,QAAQ,EAAE,SAAS,CAAC,WAAW;cAE9C,QAAQ,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BAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpF,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC"}
package/index.js CHANGED
@@ -3,50 +3,96 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Plugin = void 0;
4
4
  exports.connect = connect;
5
5
  exports.launch = launch;
6
- exports.addPlugin = addPlugin;
7
- exports.clearPlugins = clearPlugins;
8
- exports.anonymizeUserAgent = anonymizeUserAgent;
9
- exports.avoidDetection = avoidDetection;
10
- exports.blockResources = blockResources;
11
- exports.disableDialogs = disableDialogs;
12
- exports.manageCookies = manageCookies;
13
- exports.manageLocalStorage = manageLocalStorage;
14
- exports.solveRecaptchas = solveRecaptchas;
15
6
  /* eslint-disable prefer-rest-params */
16
7
  const events = require("events");
17
8
  // Puppeteer Defaults
18
9
  const Puppeteer = require("puppeteer");
19
- const browserEvents = new events.EventEmitter();
20
10
  async function connect(options) {
21
11
  const browser = await Puppeteer.connect(options || {});
22
- for (const plugin of plugins) {
23
- await plugin.init(browser);
24
- }
25
- const _close = browser.close;
26
- browser.close = async () => {
27
- await _close.apply(browser);
28
- browserEvents.emit('close');
29
- };
30
- return browser;
12
+ return createBrowser(browser);
31
13
  }
32
- /** The method launches a browser instance with given arguments. The browser will be closed when the parent node.js process is closed. */
33
14
  async function launch(options) {
34
15
  if (!options)
35
16
  options = {};
36
17
  process.env.PUPPETEER_DISABLE_HEADLESS_WARNING = 'true';
37
18
  const browser = await Puppeteer.launch({ defaultViewport: undefined, ...options });
38
- for (const plugin of plugins) {
39
- await plugin.init(browser);
40
- }
19
+ return createBrowser(browser);
20
+ }
21
+ async function createBrowser(puppeteerBrowser) {
22
+ const browser = puppeteerBrowser;
41
23
  const _close = browser.close;
42
24
  browser.close = async () => {
43
25
  await _close.apply(browser);
44
- browserEvents.emit('close');
26
+ browser.browserEvents.emit('close');
45
27
  };
28
+ const _createBrowserContext = browser.createBrowserContext;
29
+ browser.createBrowserContext = async (options) => {
30
+ const context = await _createBrowserContext.apply(browser, options);
31
+ return createBrowserContext(context);
32
+ };
33
+ addPluginSupport(browser);
46
34
  return browser;
47
35
  }
48
- // PuppeteerPro
49
- let interceptions = 0;
36
+ async function createBrowserContext(puppeteerBrowserContext) {
37
+ const browser = puppeteerBrowserContext;
38
+ const _close = browser.close;
39
+ browser.close = async () => {
40
+ await _close.apply(browser);
41
+ browser.browserEvents.emit('close');
42
+ };
43
+ addPluginSupport(browser);
44
+ return browser;
45
+ }
46
+ function addPluginSupport(browser) {
47
+ browser.plugins = [];
48
+ browser.browserEvents = new events.EventEmitter();
49
+ browser.interceptions = 0;
50
+ browser.addPlugin = async (plugin) => {
51
+ browser.plugins.push(plugin);
52
+ await plugin.init(browser);
53
+ };
54
+ browser.clearPlugins = () => {
55
+ browser.plugins.forEach(async (plugin) => {
56
+ await plugin.stop();
57
+ });
58
+ browser.plugins = [];
59
+ };
60
+ browser.anonymizeUserAgent = async () => {
61
+ const plugin = new anonymize_user_agent_1.AnonymizeUserAgentPlugin();
62
+ await browser.addPlugin(plugin);
63
+ return plugin;
64
+ };
65
+ browser.avoidDetection = async () => {
66
+ const plugin = new avoid_detection_1.AvoidDetectionPlugin();
67
+ await browser.addPlugin(plugin);
68
+ return plugin;
69
+ };
70
+ browser.blockResources = async (...resources) => {
71
+ const plugin = new block_resources_1.BlockResourcesPlugin(resources);
72
+ await browser.addPlugin(plugin);
73
+ return plugin;
74
+ };
75
+ browser.disableDialogs = async (logMessages = false) => {
76
+ const plugin = new disable_dialogs_1.DisableDialogsPlugin(logMessages);
77
+ await browser.addPlugin(plugin);
78
+ return plugin;
79
+ };
80
+ browser.manageCookies = async (opts) => {
81
+ const plugin = new manage_cookies_1.ManageCookiesPlugin(opts);
82
+ await browser.addPlugin(plugin);
83
+ return plugin;
84
+ };
85
+ browser.manageLocalStorage = async (opts) => {
86
+ const plugin = new manage_localstorage_1.ManageLocalStoragePlugin(opts);
87
+ await browser.addPlugin(plugin);
88
+ return plugin;
89
+ };
90
+ browser.solveRecaptchas = async (accessToken) => {
91
+ const plugin = new solve_recaptcha_1.SolveRecaptchaPlugin(accessToken);
92
+ await browser.addPlugin(plugin);
93
+ return plugin;
94
+ };
95
+ }
50
96
  class Plugin {
51
97
  constructor() {
52
98
  this.browser = null;
@@ -65,7 +111,7 @@ class Plugin {
65
111
  return;
66
112
  this.browser = browser;
67
113
  const offOnClose = [];
68
- browserEvents.once('close', async () => {
114
+ browser.browserEvents.once('close', async () => {
69
115
  offOnClose.forEach(fn => fn());
70
116
  this.browser = null;
71
117
  this.initialized = false;
@@ -168,8 +214,8 @@ class Plugin {
168
214
  async restart() {
169
215
  await this.beforeRestart();
170
216
  this.startCounter++;
171
- if (this.requiresInterception)
172
- interceptions++;
217
+ if (this.requiresInterception && this.browser)
218
+ this.browser.interceptions++;
173
219
  this.dependencies.forEach(x => x.restart());
174
220
  await this.afterRestart();
175
221
  }
@@ -178,9 +224,9 @@ class Plugin {
178
224
  async stop() {
179
225
  await this.beforeStop();
180
226
  this.startCounter--;
181
- if (this.requiresInterception)
182
- interceptions--;
183
- if (interceptions === 0 && this.browser) {
227
+ if (this.requiresInterception && this.browser)
228
+ this.browser.interceptions--;
229
+ if (this.browser && this.browser.interceptions === 0) {
184
230
  const pages = await this.browser.pages();
185
231
  pages.filter(x => !x.isClosed()).forEach(async (page) => {
186
232
  await page.setRequestInterception(false);
@@ -200,54 +246,11 @@ class Plugin {
200
246
  }
201
247
  }
202
248
  exports.Plugin = Plugin;
203
- let plugins = [];
204
- function addPlugin(plugin) { plugins.push(plugin); }
205
- async function clearPlugins() {
206
- plugins.forEach(async (plugin) => {
207
- await plugin.stop();
208
- });
209
- plugins = [];
210
- }
211
- const index_1 = require("./plugins/anonymize.user.agent/index");
212
- function anonymizeUserAgent() {
213
- const plugin = new index_1.AnonymizeUserAgentPlugin();
214
- plugins.push(plugin);
215
- return plugin;
216
- }
249
+ const anonymize_user_agent_1 = require("./plugins/anonymize.user.agent");
217
250
  const avoid_detection_1 = require("./plugins/avoid.detection");
218
- function avoidDetection() {
219
- const plugin = new avoid_detection_1.AvoidDetectionPlugin();
220
- plugins.push(plugin);
221
- return plugin;
222
- }
223
251
  const block_resources_1 = require("./plugins/block.resources");
224
- function blockResources(...resources) {
225
- const plugin = new block_resources_1.BlockResourcesPlugin(resources);
226
- plugins.push(plugin);
227
- return plugin;
228
- }
229
252
  const disable_dialogs_1 = require("./plugins/disable.dialogs");
230
- function disableDialogs(logMessages = false) {
231
- const plugin = new disable_dialogs_1.DisableDialogsPlugin(logMessages);
232
- plugins.push(plugin);
233
- return plugin;
234
- }
235
253
  const manage_cookies_1 = require("./plugins/manage.cookies");
236
- function manageCookies(opts) {
237
- const plugin = new manage_cookies_1.ManageCookiesPlugin(opts);
238
- plugins.push(plugin);
239
- return plugin;
240
- }
241
254
  const manage_localstorage_1 = require("./plugins/manage.localstorage");
242
- function manageLocalStorage(opts) {
243
- const plugin = new manage_localstorage_1.ManageLocalStoragePlugin(opts);
244
- plugins.push(plugin);
245
- return plugin;
246
- }
247
255
  const solve_recaptcha_1 = require("./plugins/solve.recaptcha");
248
- function solveRecaptchas(accessToken) {
249
- const plugin = new solve_recaptcha_1.SolveRecaptchaPlugin(accessToken);
250
- plugins.push(plugin);
251
- return plugin;
252
- }
253
256
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAQA,0BAcC;AAGD,wBAiBC;AAkMD,8BAAmE;AACnE,oCAMC;AAGD,gDAIC;AAGD,wCAIC;AAGD,wCAIC;AAGD,wCAIC;AAGD,sCAIC;AAGD,gDAIC;AAGD,0CAIC;AApSD,uCAAuC;AACvC,iCAAiC;AAEjC,qBAAqB;AACrB,uCAAuC;AAEvC,MAAM,aAAa,GAAG,IAAI,MAAM,CAAC,YAAY,EA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ACjE,SAAgB,eAAe,CAAC,WAAmB;IACjD,MAAM,MAAM,GAAG,IAAI,sCAAoB,CAAC,WAAW,CAAC,CAAC;IACrD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrB,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/* eslint-disable prefer-rest-params */\nimport * as events from 'events';\n\n// Puppeteer Defaults\nimport * as Puppeteer from 'puppeteer';\n\nconst browserEvents = new events.EventEmitter();\n\nexport async function connect(options?: Puppeteer.ConnectOptions): Promise<Puppeteer.Browser> {\n const browser = await Puppeteer.connect(options || {});\n\n for (const plugin of plugins) {\n await plugin.init(browser);\n }\n\n const _close = browser.close;\n browser.close = async () => {\n await _close.apply(browser);\n browserEvents.emit('close');\n };\n\n return browser;\n}\n\n/** The method launches a browser instance with given arguments. The browser will be closed when the parent node.js process is closed. */\nexport async function launch(options?: Puppeteer.LaunchOptions & Puppeteer.ConnectOptions): Promise<Puppeteer.Browser> {\n if (!options) options = {};\n\n process.env.PUPPETEER_DISABLE_HEADLESS_WARNING = 'true';\n const browser = await Puppeteer.launch({ defaultViewport: undefined, ...options });\n\n for (const plugin of plugins) {\n await plugin.init(browser);\n }\n\n const _close = browser.close;\n browser.close = async () => {\n await _close.apply(browser);\n browserEvents.emit('close');\n };\n\n return browser;\n}\n\n// PuppeteerPro\nlet interceptions = 0;\nexport class Plugin {\n protected browser: Puppeteer.Browser | null = null;\n private initialized = false;\n private startCounter = 0;\n protected dependencies: Plugin[] = [];\n protected requiresInterception = false;\n\n get isInitialized() { return this.initialized; }\n get isStopped() { return this.startCounter === 0; }\n\n async addDependency(plugin: Plugin) {\n this.dependencies.push(plugin);\n }\n\n async init(browser: Puppeteer.Browser) {\n if (this.initialized) return;\n\n this.browser = browser;\n\n const offOnClose: (() => void)[] = [];\n browserEvents.once('close', async () => {\n offOnClose.forEach(fn => fn());\n\n this.browser = null;\n this.initialized = false;\n this.startCounter = 0;\n\n await this.onClose();\n });\n\n this.startCounter++;\n\n const thisOnTargetCreated = this.onTargetCreated.bind(this);\n browser.on('targetcreated', thisOnTargetCreated);\n offOnClose.push(() => browser.off('targetcreated', thisOnTargetCreated));\n\n this.initialized = true;\n\n this.dependencies.forEach(x => x.init(browser));\n\n return this.afterLaunch(browser);\n }\n\n protected async afterLaunch(_browser: Puppeteer.Browser) { null; }\n protected async onClose() { null; }\n\n protected async onTargetCreated(target: Puppeteer.Target) {\n if (this.isStopped) return;\n\n if (target.type() !== 'page') return;\n const page = await target.page() as Puppeteer.Page;\n if (page.isClosed()) return;\n\n const offOnClose: (() => void)[] = [];\n page.once('close', async () => {\n offOnClose.forEach(fn => fn());\n });\n\n const requestHandlers: ((request: any) => void)[] = [];\n page.on('request', request => {\n const _respond = request.respond;\n let responded = 0;\n let respondArgs: IArguments;\n\n const _abort = request.abort;\n let aborted = 0;\n let abortArgs: IArguments;\n\n const _continue = request.continue;\n let continued = 0;\n let continueArgs: IArguments;\n\n const handleRequest = async function () {\n const total = responded + aborted + continued;\n\n if (!(request as any)._interceptionHandled) {\n if (responded === 1) await _respond.apply(request, respondArgs);\n else if (responded === 0 && aborted >= 1 && total === requestHandlers.length) await _abort.apply(request, abortArgs);\n else if (continued === requestHandlers.length) await _continue.apply(request, continueArgs);\n }\n };\n\n request.respond = async function () { responded++; respondArgs = respondArgs || arguments; await handleRequest(); };\n request.abort = async function () { aborted++; abortArgs = abortArgs || arguments; await handleRequest(); };\n request.continue = async function () { continued++; continueArgs = continueArgs || arguments; await handleRequest(); };\n\n requestHandlers.forEach(handler => handler(request));\n });\n\n const _pageOn = page.on;\n page.on = function async(eventName, handler) {\n if (eventName === 'request') {\n requestHandlers.push(handler);\n\n return page;\n } else {\n return _pageOn.call(page, eventName, handler);\n }\n };\n\n if (this.requiresInterception) {\n await page.setRequestInterception(true);\n\n const thisOnRequest = this.onRequest.bind(this);\n page.on('request', thisOnRequest);\n offOnClose.push(() => page.off('request', thisOnRequest));\n }\n\n const thisOnDialog = this.onDialog.bind(this);\n page.on('dialog', thisOnDialog);\n offOnClose.push(() => page.off('dialog', thisOnDialog));\n\n await this.onPageCreated(page);\n }\n\n protected async onPageCreated(_page: Puppeteer.Page) { null; }\n\n protected async onRequest(request: Puppeteer.HTTPRequest) {\n const interceptionHandled = (request as any)._interceptionHandled;\n if (interceptionHandled) return;\n if (this.isStopped) return request.continue();\n\n await this.processRequest(request);\n }\n\n protected async processRequest(_request: Puppeteer.HTTPRequest) { null; }\n\n protected async onDialog(dialog: Dialog) {\n if (this.isStopped) return;\n\n const _dismiss = dialog.dismiss;\n dialog.dismiss = async () => {\n if (dialog.handled) return;\n\n await _dismiss.apply(dialog);\n };\n\n await this.processDialog(dialog);\n }\n\n protected async processDialog(_dialog: Dialog) { null; }\n\n protected async beforeRestart() { null; }\n async restart() {\n await this.beforeRestart();\n\n this.startCounter++;\n if (this.requiresInterception) interceptions++;\n\n this.dependencies.forEach(x => x.restart());\n\n await this.afterRestart();\n }\n\n protected async afterRestart() { null; }\n\n protected async beforeStop() { null; }\n async stop() {\n await this.beforeStop();\n\n this.startCounter--;\n if (this.requiresInterception) interceptions--;\n\n if (interceptions === 0 && this.browser) {\n const pages = await this.browser.pages();\n\n pages.filter(x => !x.isClosed()).forEach(async (page: Puppeteer.Page) => {\n await page.setRequestInterception(false);\n });\n }\n\n this.dependencies.forEach(x => x.stop());\n\n await this.afterStop();\n }\n\n protected async afterStop() { null; }\n\n protected async getFirstPage() {\n if (!this.browser) return null;\n\n const pages = await this.browser.pages();\n const openPages = pages.filter(x => !x.isClosed());\n const activePages = pages.filter(x => x.url() !== 'about:blank');\n\n return activePages[0] || openPages[0];\n }\n}\n\nlet plugins: Plugin[] = [];\nexport function addPlugin(plugin: Plugin) { plugins.push(plugin); }\nexport async function clearPlugins() {\n plugins.forEach(async plugin => {\n await plugin.stop();\n });\n\n plugins = [];\n}\n\nimport { AnonymizeUserAgentPlugin } from './plugins/anonymize.user.agent/index';\nexport function anonymizeUserAgent(): AnonymizeUserAgentPlugin {\n const plugin = new AnonymizeUserAgentPlugin();\n plugins.push(plugin);\n return plugin;\n}\n\nimport { AvoidDetectionPlugin } from './plugins/avoid.detection';\nexport function avoidDetection(): AvoidDetectionPlugin {\n const plugin = new AvoidDetectionPlugin();\n plugins.push(plugin);\n return plugin;\n}\n\nimport { BlockResourcesPlugin, Resource } from './plugins/block.resources';\nexport function blockResources(...resources: Resource[]): BlockResourcesPlugin {\n const plugin = new BlockResourcesPlugin(resources);\n plugins.push(plugin);\n return plugin;\n}\n\nimport { DisableDialogsPlugin } from './plugins/disable.dialogs';\nexport function disableDialogs(logMessages = false): DisableDialogsPlugin {\n const plugin = new DisableDialogsPlugin(logMessages);\n plugins.push(plugin);\n return plugin;\n}\n\nimport { ManageCookiesOption, ManageCookiesPlugin } from './plugins/manage.cookies';\nexport function manageCookies(opts: ManageCookiesOption): ManageCookiesPlugin {\n const plugin = new ManageCookiesPlugin(opts);\n plugins.push(plugin);\n return plugin;\n}\n\nimport { ManageLocalStorageOption, ManageLocalStoragePlugin } from './plugins/manage.localstorage';\nexport function manageLocalStorage(opts: ManageLocalStorageOption): ManageLocalStoragePlugin {\n const plugin = new ManageLocalStoragePlugin(opts);\n plugins.push(plugin);\n return plugin;\n}\n\nimport { SolveRecaptchaPlugin } from './plugins/solve.recaptcha';\nexport function solveRecaptchas(accessToken: string): SolveRecaptchaPlugin {\n const plugin = new SolveRecaptchaPlugin(accessToken);\n plugins.push(plugin);\n return plugin;\n}\n\ninterface Dialog extends Puppeteer.Dialog {\n handled: boolean;\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAMA,0BAIC;AAED,wBAOC;AAnBD,uCAAuC;AACvC,iCAAiC;AAEjC,qBAAqB;AACrB,uCAAuC;AAEhC,KAAK,UAAU,OAAO,CAAC,OAAkC;IAC9D,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;IAEvD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';\r\n\r\nexport async function connect(options?: Puppeteer.ConnectOptions): Promise<Browser> {\r\n const browser = await Puppeteer.connect(options || {});\r\n\r\n return createBrowser(browser);\r\n}\r\n\r\nexport async function launch(options?: Puppeteer.LaunchOptions & Puppeteer.ConnectOptions): Promise<Browser> {\r\n if (!options) options = {};\r\n\r\n process.env.PUPPETEER_DISABLE_HEADLESS_WARNING = 'true';\r\n const browser = await Puppeteer.launch({ defaultViewport: undefined, ...options });\r\n\r\n return createBrowser(browser);\r\n}\r\n\r\nasync function createBrowser(puppeteerBrowser: Puppeteer.Browser): Promise<Browser> {\r\n const browser = puppeteerBrowser as Browser;\r\n\r\n const _close = browser.close;\r\n browser.close = async () => {\r\n await _close.apply(browser);\r\n browser.browserEvents.emit('close');\r\n };\r\n\r\n const _createBrowserContext = browser.createBrowserContext;\r\n browser.createBrowserContext = async (options?: Puppeteer.BrowserContextOptions) => {\r\n const context: Puppeteer.BrowserContext = await _createBrowserContext.apply(browser, options);\r\n\r\n return createBrowserContext(context);\r\n };\r\n\r\n addPluginSupport(browser);\r\n\r\n return browser;\r\n}\r\n\r\nasync function createBrowserContext(puppeteerBrowserContext: Puppeteer.BrowserContext): Promise<BrowserContext> {\r\n const browser = puppeteerBrowserContext as BrowserContext;\r\n\r\n const _close = browser.close;\r\n browser.close = async () => {\r\n await _close.apply(browser);\r\n browser.browserEvents.emit('close');\r\n };\r\n\r\n addPluginSupport(browser);\r\n\r\n return browser;\r\n}\r\n\r\nfunction addPluginSupport(browser: Browser | BrowserContext) {\r\n browser.plugins = [];\r\n browser.browserEvents = new events.EventEmitter();\r\n browser.interceptions = 0;\r\n\r\n browser.addPlugin = async (plugin: Plugin) => {\r\n browser.plugins.push(plugin);\r\n await plugin.init(browser);\r\n };\r\n\r\n browser.clearPlugins = () => {\r\n browser.plugins.forEach(async plugin => {\r\n await plugin.stop();\r\n });\r\n\r\n browser.plugins = [];\r\n };\r\n\r\n browser.anonymizeUserAgent = async (): Promise<AnonymizeUserAgentPlugin> => {\r\n const plugin = new AnonymizeUserAgentPlugin();\r\n await browser.addPlugin(plugin);\r\n return plugin;\r\n };\r\n\r\n browser.avoidDetection = async (): Promise<AvoidDetectionPlugin> => {\r\n const plugin = new AvoidDetectionPlugin();\r\n await browser.addPlugin(plugin);\r\n return plugin;\r\n };\r\n\r\n browser.blockResources = async (...resources: Resource[]): Promise<BlockResourcesPlugin> => {\r\n const plugin = new BlockResourcesPlugin(resources);\r\n await browser.addPlugin(plugin);\r\n return plugin;\r\n };\r\n\r\n browser.disableDialogs = async (logMessages = false): Promise<DisableDialogsPlugin> => {\r\n const plugin = new DisableDialogsPlugin(logMessages);\r\n await browser.addPlugin(plugin);\r\n return plugin;\r\n };\r\n\r\n browser.manageCookies = async (opts: ManageCookiesOption): Promise<ManageCookiesPlugin> => {\r\n const plugin = new ManageCookiesPlugin(opts);\r\n await browser.addPlugin(plugin);\r\n return plugin;\r\n };\r\n\r\n browser.manageLocalStorage = async (opts: ManageLocalStorageOption): Promise<ManageLocalStoragePlugin> => {\r\n const plugin = new ManageLocalStoragePlugin(opts);\r\n await browser.addPlugin(plugin);\r\n return plugin;\r\n };\r\n\r\n browser.solveRecaptchas = async (accessToken: string): Promise<SolveRecaptchaPlugin> => {\r\n const plugin = new SolveRecaptchaPlugin(accessToken);\r\n await browser.addPlugin(plugin);\r\n return plugin;\r\n };\r\n}\r\n\r\n// PuppeteerPro\r\nexport interface Browser extends Puppeteer.Browser, Pluginable {\r\n createBrowserContext(options?: Puppeteer.BrowserContextOptions): Promise<BrowserContext>;\r\n}\r\n\r\nexport interface BrowserContext extends Puppeteer.BrowserContext, Pluginable {\r\n}\r\n\r\nexport class Plugin {\r\n protected browser: Browser | BrowserContext | null = null;\r\n private initialized = false;\r\n private startCounter = 0;\r\n protected dependencies: Plugin[] = [];\r\n protected requiresInterception = false;\r\n\r\n get isInitialized() { return this.initialized; }\r\n get isStopped() { return this.startCounter === 0; }\r\n\r\n async addDependency(plugin: Plugin) {\r\n this.dependencies.push(plugin);\r\n }\r\n\r\n async init(browser: Browser | BrowserContext) {\r\n if (this.initialized) return;\r\n\r\n this.browser = browser;\r\n\r\n const offOnClose: (() => void)[] = [];\r\n browser.browserEvents.once('close', async () => {\r\n offOnClose.forEach(fn => fn());\r\n\r\n this.browser = null;\r\n this.initialized = false;\r\n this.startCounter = 0;\r\n\r\n await this.onClose();\r\n });\r\n\r\n this.startCounter++;\r\n\r\n const thisOnTargetCreated = this.onTargetCreated.bind(this);\r\n browser.on('targetcreated', thisOnTargetCreated);\r\n offOnClose.push(() => browser.off('targetcreated', thisOnTargetCreated));\r\n\r\n this.initialized = true;\r\n\r\n this.dependencies.forEach(x => x.init(browser));\r\n\r\n return this.afterLaunch(browser);\r\n }\r\n\r\n protected async afterLaunch(_browser: Browser | BrowserContext) { null; }\r\n protected async onClose() { null; }\r\n\r\n protected async onTargetCreated(target: Puppeteer.Target) {\r\n if (this.isStopped) return;\r\n\r\n if (target.type() !== 'page') return;\r\n const page = await target.page() as Puppeteer.Page;\r\n if (page.isClosed()) return;\r\n\r\n const offOnClose: (() => void)[] = [];\r\n page.once('close', async () => {\r\n offOnClose.forEach(fn => fn());\r\n });\r\n\r\n const requestHandlers: ((request: any) => void)[] = [];\r\n page.on('request', request => {\r\n const _respond = request.respond;\r\n let responded = 0;\r\n let respondArgs: IArguments;\r\n\r\n const _abort = request.abort;\r\n let aborted = 0;\r\n let abortArgs: IArguments;\r\n\r\n const _continue = request.continue;\r\n let continued = 0;\r\n let continueArgs: IArguments;\r\n\r\n const handleRequest = async function () {\r\n const total = responded + aborted + continued;\r\n\r\n if (!(request as any)._interceptionHandled) {\r\n if (responded === 1) await _respond.apply(request, respondArgs);\r\n else if (responded === 0 && aborted >= 1 && total === requestHandlers.length) await _abort.apply(request, abortArgs);\r\n else if (continued === requestHandlers.length) await _continue.apply(request, continueArgs);\r\n }\r\n };\r\n\r\n request.respond = async function () { responded++; respondArgs = respondArgs || arguments; await handleRequest(); };\r\n request.abort = async function () { aborted++; abortArgs = abortArgs || arguments; await handleRequest(); };\r\n request.continue = async function () { continued++; continueArgs = continueArgs || arguments; await handleRequest(); };\r\n\r\n requestHandlers.forEach(handler => handler(request));\r\n });\r\n\r\n const _pageOn = page.on;\r\n page.on = function async(eventName, handler) {\r\n if (eventName === 'request') {\r\n requestHandlers.push(handler);\r\n\r\n return page;\r\n } else {\r\n return _pageOn.call(page, eventName, handler);\r\n }\r\n };\r\n\r\n if (this.requiresInterception) {\r\n await page.setRequestInterception(true);\r\n\r\n const thisOnRequest = this.onRequest.bind(this);\r\n page.on('request', thisOnRequest);\r\n offOnClose.push(() => page.off('request', thisOnRequest));\r\n }\r\n\r\n const thisOnDialog = this.onDialog.bind(this);\r\n page.on('dialog', thisOnDialog);\r\n offOnClose.push(() => page.off('dialog', thisOnDialog));\r\n\r\n await this.onPageCreated(page);\r\n }\r\n\r\n protected async onPageCreated(_page: Puppeteer.Page) { null; }\r\n\r\n protected async onRequest(request: Puppeteer.HTTPRequest) {\r\n const interceptionHandled = (request as any)._interceptionHandled;\r\n if (interceptionHandled) return;\r\n if (this.isStopped) return request.continue();\r\n\r\n await this.processRequest(request);\r\n }\r\n\r\n protected async processRequest(_request: Puppeteer.HTTPRequest) { null; }\r\n\r\n protected async onDialog(dialog: Dialog) {\r\n if (this.isStopped) return;\r\n\r\n const _dismiss = dialog.dismiss;\r\n dialog.dismiss = async () => {\r\n if (dialog.handled) return;\r\n\r\n await _dismiss.apply(dialog);\r\n };\r\n\r\n await this.processDialog(dialog);\r\n }\r\n\r\n protected async processDialog(_dialog: Dialog) { null; }\r\n\r\n protected async beforeRestart() { null; }\r\n async restart() {\r\n await this.beforeRestart();\r\n\r\n this.startCounter++;\r\n if (this.requiresInterception && this.browser) this.browser.interceptions++;\r\n\r\n this.dependencies.forEach(x => x.restart());\r\n\r\n await this.afterRestart();\r\n }\r\n\r\n protected async afterRestart() { null; }\r\n\r\n protected async beforeStop() { null; }\r\n async stop() {\r\n await this.beforeStop();\r\n\r\n this.startCounter--;\r\n if (this.requiresInterception && this.browser) this.browser.interceptions--;\r\n\r\n if (this.browser && this.browser.interceptions === 0) {\r\n const pages = await this.browser.pages();\r\n\r\n pages.filter(x => !x.isClosed()).forEach(async (page: Puppeteer.Page) => {\r\n await page.setRequestInterception(false);\r\n });\r\n }\r\n\r\n this.dependencies.forEach(x => x.stop());\r\n\r\n await this.afterStop();\r\n }\r\n\r\n protected async afterStop() { null; }\r\n\r\n protected async getFirstPage() {\r\n if (!this.browser) return null;\r\n\r\n const pages = await this.browser.pages();\r\n const openPages = pages.filter(x => !x.isClosed());\r\n const activePages = pages.filter(x => x.url() !== 'about:blank');\r\n\r\n return activePages[0] || openPages[0];\r\n }\r\n}\r\n\r\ninterface Pluginable {\r\n plugins: Plugin[];\r\n browserEvents: events.EventEmitter;\r\n interceptions: number;\r\n\r\n addPlugin: (plugin: Plugin) => Promise<void>;\r\n clearPlugins: () => void;\r\n anonymizeUserAgent: () => Promise<AnonymizeUserAgentPlugin>;\r\n avoidDetection: () => Promise<AvoidDetectionPlugin>;\r\n blockResources: (...resources: Resource[]) => Promise<BlockResourcesPlugin>;\r\n disableDialogs: (logMessages?: boolean) => Promise<DisableDialogsPlugin>;\r\n manageCookies: (opts: ManageCookiesOption) => Promise<ManageCookiesPlugin>;\r\n manageLocalStorage: (opts: ManageLocalStorageOption) => Promise<ManageLocalStoragePlugin>;\r\n solveRecaptchas: (accessToken: string) => Promise<SolveRecaptchaPlugin>;\r\n}\r\n\r\ninterface Dialog extends Puppeteer.Dialog {\r\n handled: boolean;\r\n}\r\n\r\nimport { AnonymizeUserAgentPlugin } from './plugins/anonymize.user.agent';\r\nimport { AvoidDetectionPlugin } from './plugins/avoid.detection';\r\nimport { BlockResourcesPlugin, Resource } from './plugins/block.resources';\r\nimport { DisableDialogsPlugin } from './plugins/disable.dialogs';\r\nimport { ManageCookiesOption, ManageCookiesPlugin } from './plugins/manage.cookies';\r\nimport { ManageLocalStorageOption, ManageLocalStoragePlugin } from './plugins/manage.localstorage';\r\nimport { SolveRecaptchaPlugin } from './plugins/solve.recaptcha';\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puppeteer-pro",
3
- "version": "1.9.10",
3
+ "version": "2.0.0",
4
4
  "description": "A simple puppeteer wrapper to enable useful plugins with ease",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -43,14 +43,14 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/jest": "^29.5.14",
46
- "@types/node": "^22.15.2",
46
+ "@types/node": "^22.15.29",
47
47
  "@types/user-agents": "^1.0.4",
48
48
  "copyfiles": "^2.4.1",
49
49
  "dotenv-safe": "^9.1.0",
50
- "eslint-config-final": "^1.5.15",
50
+ "eslint-config-final": "^1.5.21",
51
51
  "jest": "^29.7.0",
52
- "puppeteer": "^24.7.2",
53
- "ts-jest": "^29.3.2",
52
+ "puppeteer": "^24.10.0",
53
+ "ts-jest": "^29.3.4",
54
54
  "ts-node": "^10.9.2",
55
55
  "typescript": "^5.8.3"
56
56
  }
@@ -1,10 +1,10 @@
1
1
  import * as Puppeteer from 'puppeteer';
2
- import { Plugin } from '../../index';
2
+ import { Browser, BrowserContext, Plugin } from '../..';
3
3
  export declare class AnonymizeUserAgentPlugin extends Plugin {
4
4
  private pages;
5
5
  private userAgent?;
6
6
  constructor();
7
- protected afterLaunch(browser: Puppeteer.Browser): Promise<void>;
7
+ protected afterLaunch(browser: Browser | BrowserContext): Promise<void>;
8
8
  protected onClose(): Promise<void>;
9
9
  protected onPageCreated(page: Puppeteer.Page): Promise<void>;
10
10
  protected beforeRestart(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/anonymize.user.agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAIvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAUrC,qBAAa,wBAAyB,SAAQ,MAAM;IAClD,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,SAAS,CAAC,CAAS;;cAYX,WAAW,CAAC,OAAO,EAAE,SAAS,CAAC,OAAO;cAStC,OAAO;cAIP,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI;cASlC,aAAa;cAQb,SAAS;CAO1B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/anonymize.user.agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAIvC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAUxD,qBAAa,wBAAyB,SAAQ,MAAM;IAClD,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,SAAS,CAAC,CAAS;;cAYX,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc;cAS7C,OAAO;cAIP,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI;cASlC,aAAa;cAQb,SAAS;CAO1B"}
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AnonymizeUserAgentPlugin = void 0;
4
4
  // eslint-disable-next-line @typescript-eslint/no-require-imports
5
5
  const UserAgent = require("user-agents");
6
- const index_1 = require("../../index");
6
+ const __1 = require("../..");
7
7
  const sleep = (time) => { return new Promise(resolve => { setTimeout(resolve, time); }); };
8
- class AnonymizeUserAgentPlugin extends index_1.Plugin {
8
+ class AnonymizeUserAgentPlugin extends __1.Plugin {
9
9
  constructor() {
10
10
  super();
11
11
  this.pages = [];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/anonymize.user.agent/index.ts"],"names":[],"mappings":";;;AACA,iEAAiE;AACjE,yCAA0C;AAE1C,uCAAqC;AAErC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,GAAG,OAAO,IAAI,OAAO,CAAC,OAAO,C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C;QAE3D,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC;IAES,KAAK,CAAC,aAAa;QAC3B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;gBAAE,SAAS;YAErC,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAES,KAAK,CAAC,SAAS;QACvB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;gBAAE,SAAS;YAErC,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;CACF;AAnDD,4DAmDC","sourcesContent":["import * as Puppeteer from 'puppeteer';\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nimport UserAgent = require('user-agents');\n\nimport { Plugin } from '../../index';\n\nconst sleep = (time: number) => { return new Promise(resolve => { setTimeout(resolve, time); }); };\n\ninterface PageUserAgent {\n target: Puppeteer.Page;\n userAgent: string;\n newUserAgent: string;\n}\n\nexport class AnonymizeUserAgentPlugin extends Plugin {\n private pages: PageUserAgent[] = [];\n private userAgent?: string;\n\n constructor() {\n super();\n\n try {\n this.userAgent = new UserAgent({ vendor: 'Google Inc.', platform: 'Win32' }).toString();\n } catch (_ex) {\n console.warn('Could not create a random user agent');\n }\n }\n\n protected async afterLaunch(browser: Puppeteer.Browser) {\n const _newPage = browser.newPage;\n browser.newPage = async (): Promise<Puppeteer.Page> => {\n const page = await _newPage.apply(browser);\n await sleep(100); // Sleep to allow user agent to set\n return page;\n };\n }\n\n protected async onClose() {\n this.pages = [];\n }\n\n protected async onPageCreated(page: Puppeteer.Page) {\n const userAgent = await page.browser().userAgent();\n const newUserAgent = this.userAgent || userAgent.replace('HeadlessChrome/', 'Chrome/').replace(/\\(([^)]+)\\)/, '(Windows NT 10.0; Win64; x64)');\n\n this.pages.push({ target: page, userAgent, newUserAgent });\n\n await page.setUserAgent(newUserAgent);\n }\n\n protected async beforeRestart() {\n for (const page of this.pages) {\n if (page.target.isClosed()) continue;\n\n await page.target.setUserAgent(page.newUserAgent);\n }\n }\n\n protected async afterStop() {\n for (const page of this.pages) {\n if (page.target.isClosed()) continue;\n\n await page.target.setUserAgent(page.userAgent);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/anonymize.user.agent/index.ts"],"names":[],"mappings":";;;AACA,iEAAiE;AACjE,yCAA0C;AAE1C,6BAAwD;AAExD,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,GAAG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAQnG,MAAa,wBAAyB,SAAQ,UAAM;IAIlD;QACE,KAAK,EAAE,CAAC;QAJF,UAAK,GAAoB,EAAE,CAAC;QAMlC,IAAI,CAAC;YACH,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC1F,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAES,KAAK,CAAC,WAAW,CAAC,OAAiC;QAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;QACjC,OAAO,CAAC,OAAO,GAAG,KAAK,IAA6B,EAAE;YACpD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC3C,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,mCAAmC;YACrD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,OAAO;QACrB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;IAES,KAAK,CAAC,aAAa,CAAC,IAAoB;QAChD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,CAAC;QACnD,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,OAAO,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,+BAA+B,CAAC,CAAC;QAE/I,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;QAE3D,MAAM,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC;IAES,KAAK,CAAC,aAAa;QAC3B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;gBAAE,SAAS;YAErC,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAES,KAAK,CAAC,SAAS;QACvB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;gBAAE,SAAS;YAErC,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;CACF;AAnDD,4DAmDC","sourcesContent":["import * as Puppeteer from 'puppeteer';\r\n// eslint-disable-next-line @typescript-eslint/no-require-imports\r\nimport UserAgent = require('user-agents');\r\n\r\nimport { Browser, BrowserContext, Plugin } from '../..';\r\n\r\nconst sleep = (time: number) => { return new Promise(resolve => { setTimeout(resolve, time); }); };\r\n\r\ninterface PageUserAgent {\r\n target: Puppeteer.Page;\r\n userAgent: string;\r\n newUserAgent: string;\r\n}\r\n\r\nexport class AnonymizeUserAgentPlugin extends Plugin {\r\n private pages: PageUserAgent[] = [];\r\n private userAgent?: string;\r\n\r\n constructor() {\r\n super();\r\n\r\n try {\r\n this.userAgent = new UserAgent({ vendor: 'Google Inc.', platform: 'Win32' }).toString();\r\n } catch (_ex) {\r\n console.warn('Could not create a random user agent');\r\n }\r\n }\r\n\r\n protected async afterLaunch(browser: Browser | BrowserContext) {\r\n const _newPage = browser.newPage;\r\n browser.newPage = async (): Promise<Puppeteer.Page> => {\r\n const page = await _newPage.apply(browser);\r\n await sleep(100); // Sleep to allow user agent to set\r\n return page;\r\n };\r\n }\r\n\r\n protected async onClose() {\r\n this.pages = [];\r\n }\r\n\r\n protected async onPageCreated(page: Puppeteer.Page) {\r\n const userAgent = await page.browser().userAgent();\r\n const newUserAgent = this.userAgent || userAgent.replace('HeadlessChrome/', 'Chrome/').replace(/\\(([^)]+)\\)/, '(Windows NT 10.0; Win64; x64)');\r\n\r\n this.pages.push({ target: page, userAgent, newUserAgent });\r\n\r\n await page.setUserAgent(newUserAgent);\r\n }\r\n\r\n protected async beforeRestart() {\r\n for (const page of this.pages) {\r\n if (page.target.isClosed()) continue;\r\n\r\n await page.target.setUserAgent(page.newUserAgent);\r\n }\r\n }\r\n\r\n protected async afterStop() {\r\n for (const page of this.pages) {\r\n if (page.target.isClosed()) continue;\r\n\r\n await page.target.setUserAgent(page.userAgent);\r\n }\r\n }\r\n}\r\n"]}
@@ -1,6 +1,6 @@
1
1
  import * as Puppeteer from 'puppeteer';
2
- import { Plugin } from '../../index';
3
- import { AnonymizeUserAgentPlugin } from './../anonymize.user.agent/index';
2
+ import { Plugin } from '../..';
3
+ import { AnonymizeUserAgentPlugin } from './../anonymize.user.agent';
4
4
  export declare class AvoidDetectionPlugin extends Plugin {
5
5
  dependencies: AnonymizeUserAgentPlugin[];
6
6
  protected onPageCreated(page: Puppeteer.Page): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/avoid.detection/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAM3E,qBAAa,oBAAqB,SAAQ,MAAM;IAC9C,YAAY,6BAAoC;cAEhC,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI;CAKnD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/avoid.detection/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAMrE,qBAAa,oBAAqB,SAAQ,MAAM;IAC9C,YAAY,6BAAoC;cAEhC,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI;CAKnD"}
@@ -3,15 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AvoidDetectionPlugin = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
- const index_1 = require("../../index");
7
- const index_2 = require("./../anonymize.user.agent/index");
6
+ const __1 = require("../..");
7
+ const anonymize_user_agent_1 = require("./../anonymize.user.agent");
8
8
  const injectionsFolder = (0, path_1.resolve)(`${__dirname}/injections`);
9
9
  // eslint-disable-next-line @typescript-eslint/no-require-imports
10
10
  const injections = (0, fs_1.readdirSync)(injectionsFolder).map(fileName => require(`${injectionsFolder}/${fileName}`));
11
- class AvoidDetectionPlugin extends index_1.Plugin {
11
+ class AvoidDetectionPlugin extends __1.Plugin {
12
12
  constructor() {
13
13
  super(...arguments);
14
- this.dependencies = [new index_2.AnonymizeUserAgentPlugin()];
14
+ this.dependencies = [new anonymize_user_agent_1.AnonymizeUserAgentPlugin()];
15
15
  }
16
16
  async onPageCreated(page) {
17
17
  for (const injection of injections) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/avoid.detection/index.ts"],"names":[],"mappings":";;;AAAA,2BAAiC;AACjC,+BAA8C;AAG9C,uCAAqC;AACrC,2DAA2E;AAE3E,MAAM,gBAAgB,GAAG,IAAA,cAAW,EAAC,GAAG,SAAS,aAAa,CAAC,CAAC;AAChE,iEAAiE;AACjE,MAAM,UAAU,GAAG,IAAA,gBAAW,EAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,gBAAgB,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC;AAE7G,MAAa,oBAAqB,SAAQ,cAAM;IAAhD;;QACE,iBAAY,GAAG,CAAC,IAAI,gCAAwB,EAAE,CAAC,CAAC;IAOlD,CAAC;IALW,KAAK,CAAC,aAAa,CAAC,IAAoB;QAChD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAAE,MAAM,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;QACvF,CAAC;IACH,CAAC;CACF;AARD,oDAQC","sourcesContent":["import { readdirSync } from 'fs';\nimport { resolve as resolvePath } from 'path';\nimport * as Puppeteer from 'puppeteer';\n\nimport { Plugin } from '../../index';\nimport { AnonymizeUserAgentPlugin } from './../anonymize.user.agent/index';\n\nconst injectionsFolder = resolvePath(`${__dirname}/injections`);\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst injections = readdirSync(injectionsFolder).map(fileName => require(`${injectionsFolder}/${fileName}`));\n\nexport class AvoidDetectionPlugin extends Plugin {\n dependencies = [new AnonymizeUserAgentPlugin()];\n\n protected async onPageCreated(page: Puppeteer.Page) {\n for (const injection of injections) {\n if (!this.isStopped && !page.isClosed()) await page.evaluateOnNewDocument(injection);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/avoid.detection/index.ts"],"names":[],"mappings":";;;AAAA,2BAAiC;AACjC,+BAA8C;AAG9C,6BAA+B;AAC/B,oEAAqE;AAErE,MAAM,gBAAgB,GAAG,IAAA,cAAW,EAAC,GAAG,SAAS,aAAa,CAAC,CAAC;AAChE,iEAAiE;AACjE,MAAM,UAAU,GAAG,IAAA,gBAAW,EAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,gBAAgB,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC;AAE7G,MAAa,oBAAqB,SAAQ,UAAM;IAAhD;;QACE,iBAAY,GAAG,CAAC,IAAI,+CAAwB,EAAE,CAAC,CAAC;IAOlD,CAAC;IALW,KAAK,CAAC,aAAa,CAAC,IAAoB;QAChD,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;YACnC,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAAE,MAAM,IAAI,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;QACvF,CAAC;IACH,CAAC;CACF;AARD,oDAQC","sourcesContent":["import { readdirSync } from 'fs';\r\nimport { resolve as resolvePath } from 'path';\r\nimport * as Puppeteer from 'puppeteer';\r\n\r\nimport { Plugin } from '../..';\r\nimport { AnonymizeUserAgentPlugin } from './../anonymize.user.agent';\r\n\r\nconst injectionsFolder = resolvePath(`${__dirname}/injections`);\r\n// eslint-disable-next-line @typescript-eslint/no-require-imports\r\nconst injections = readdirSync(injectionsFolder).map(fileName => require(`${injectionsFolder}/${fileName}`));\r\n\r\nexport class AvoidDetectionPlugin extends Plugin {\r\n dependencies = [new AnonymizeUserAgentPlugin()];\r\n\r\n protected async onPageCreated(page: Puppeteer.Page) {\r\n for (const injection of injections) {\r\n if (!this.isStopped && !page.isClosed()) await page.evaluateOnNewDocument(injection);\r\n }\r\n }\r\n}\r\n"]}
@@ -1,5 +1,5 @@
1
1
  import * as Puppeteer from 'puppeteer';
2
- import { Plugin } from '../../index';
2
+ import { Plugin } from '../..';
3
3
  export type Resource = 'document' | 'stylesheet' | 'image' | 'media' | 'font' | 'script' | 'texttrack' | 'xhr' | 'fetch' | 'eventsource' | 'websocket' | 'manifest' | 'other';
4
4
  export declare class BlockResourcesPlugin extends Plugin {
5
5
  requiresInterception: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/block.resources/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,KAAK,GAAG,OAAO,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC;AAC9K,qBAAa,oBAAqB,SAAQ,MAAM;IAC9C,oBAAoB,UAAQ;IAC5B,cAAc,EAAE,QAAQ,EAAE,CAAC;gBAEf,SAAS,GAAE,QAAQ,EAAO;cAMtB,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,WAAW;CAO9D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/block.resources/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,KAAK,GAAG,OAAO,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC;AAC9K,qBAAa,oBAAqB,SAAQ,MAAM;IAC9C,oBAAoB,UAAQ;IAC5B,cAAc,EAAE,QAAQ,EAAE,CAAC;gBAEf,SAAS,GAAE,QAAQ,EAAO;cAMtB,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,WAAW;CAO9D"}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BlockResourcesPlugin = void 0;
4
- const index_1 = require("../../index");
5
- class BlockResourcesPlugin extends index_1.Plugin {
4
+ const __1 = require("../..");
5
+ class BlockResourcesPlugin extends __1.Plugin {
6
6
  constructor(resources = []) {
7
7
  super();
8
8
  this.requiresInterception = true;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/block.resources/index.ts"],"names":[],"mappings":";;;AAEA,uCAAqC;AAGrC,MAAa,oBAAqB,SAAQ,cAAM;IAI9C,YAAY,YAAwB,EAAE;QACpC,KAAK,EAAE,CAAC;QAJV,yBAAoB,GAAG,IAAI,CAAC;QAM1B,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;IAClC,CAAC;IAES,KAAK,CAAC,cAAc,CAAC,OAA8B;QAC3D,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAc,CAAC,EAAE,CAAC;YACrE,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;CACF;AAjBD,oDAiBC","sourcesContent":["import * as Puppeteer from 'puppeteer';\n\nimport { Plugin } from '../../index';\n\nexport type Resource = 'document' | 'stylesheet' | 'image' | 'media' | 'font' | 'script' | 'texttrack' | 'xhr' | 'fetch' | 'eventsource' | 'websocket' | 'manifest' | 'other';\nexport class BlockResourcesPlugin extends Plugin {\n requiresInterception = true;\n blockResources: Resource[];\n\n constructor(resources: Resource[] = []) {\n super();\n\n this.blockResources = resources;\n }\n\n protected async processRequest(request: Puppeteer.HTTPRequest) {\n if (this.blockResources.includes(request.resourceType() as Resource)) {\n await request.abort();\n } else {\n await request.continue();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/block.resources/index.ts"],"names":[],"mappings":";;;AAEA,6BAA+B;AAG/B,MAAa,oBAAqB,SAAQ,UAAM;IAI9C,YAAY,YAAwB,EAAE;QACpC,KAAK,EAAE,CAAC;QAJV,yBAAoB,GAAG,IAAI,CAAC;QAM1B,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;IAClC,CAAC;IAES,KAAK,CAAC,cAAc,CAAC,OAA8B;QAC3D,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAc,CAAC,EAAE,CAAC;YACrE,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,MAAM,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC3B,CAAC;IACH,CAAC;CACF;AAjBD,oDAiBC","sourcesContent":["import * as Puppeteer from 'puppeteer';\r\n\r\nimport { Plugin } from '../..';\r\n\r\nexport type Resource = 'document' | 'stylesheet' | 'image' | 'media' | 'font' | 'script' | 'texttrack' | 'xhr' | 'fetch' | 'eventsource' | 'websocket' | 'manifest' | 'other';\r\nexport class BlockResourcesPlugin extends Plugin {\r\n requiresInterception = true;\r\n blockResources: Resource[];\r\n\r\n constructor(resources: Resource[] = []) {\r\n super();\r\n\r\n this.blockResources = resources;\r\n }\r\n\r\n protected async processRequest(request: Puppeteer.HTTPRequest) {\r\n if (this.blockResources.includes(request.resourceType() as Resource)) {\r\n await request.abort();\r\n } else {\r\n await request.continue();\r\n }\r\n }\r\n}\r\n"]}
@@ -1,5 +1,5 @@
1
1
  import * as Puppeteer from 'puppeteer';
2
- import { Plugin } from '../../index';
2
+ import { Plugin } from '../..';
3
3
  export declare class DisableDialogsPlugin extends Plugin {
4
4
  logMessages: boolean;
5
5
  constructor(logMessages?: boolean);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/disable.dialogs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,qBAAa,oBAAqB,SAAQ,MAAM;IAC9C,WAAW,EAAE,OAAO,CAAC;gBAET,WAAW,UAAQ;cAMf,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM;CAOvD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/disable.dialogs/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,qBAAa,oBAAqB,SAAQ,MAAM;IAC9C,WAAW,EAAE,OAAO,CAAC;gBAET,WAAW,UAAQ;cAMf,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM;CAOvD"}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DisableDialogsPlugin = void 0;
4
- const index_1 = require("../../index");
5
- class DisableDialogsPlugin extends index_1.Plugin {
4
+ const __1 = require("../..");
5
+ class DisableDialogsPlugin extends __1.Plugin {
6
6
  constructor(logMessages = false) {
7
7
  super();
8
8
  this.logMessages = logMessages;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/disable.dialogs/index.ts"],"names":[],"mappings":";;;AAEA,uCAAqC;AAErC,MAAa,oBAAqB,SAAQ,cAAM;IAG9C,YAAY,WAAW,GAAG,KAAK;QAC7B,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAES,KAAK,CAAC,aAAa,CAAC,MAAwB;QACpD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO,CAAC,GAAG,CAAC,mBAAmB,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF;AAhBD,oDAgBC","sourcesContent":["import * as Puppeteer from 'puppeteer';\n\nimport { Plugin } from '../../index';\n\nexport class DisableDialogsPlugin extends Plugin {\n logMessages: boolean;\n\n constructor(logMessages = false) {\n super();\n\n this.logMessages = logMessages;\n }\n\n protected async processDialog(dialog: Puppeteer.Dialog) {\n if (this.logMessages) {\n console.log(`Dialog message: ${dialog.message()}`);\n }\n\n await dialog.dismiss();\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/disable.dialogs/index.ts"],"names":[],"mappings":";;;AAEA,6BAA+B;AAE/B,MAAa,oBAAqB,SAAQ,UAAM;IAG9C,YAAY,WAAW,GAAG,KAAK;QAC7B,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAES,KAAK,CAAC,aAAa,CAAC,MAAwB;QACpD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO,CAAC,GAAG,CAAC,mBAAmB,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF;AAhBD,oDAgBC","sourcesContent":["import * as Puppeteer from 'puppeteer';\r\n\r\nimport { Plugin } from '../..';\r\n\r\nexport class DisableDialogsPlugin extends Plugin {\r\n logMessages: boolean;\r\n\r\n constructor(logMessages = false) {\r\n super();\r\n\r\n this.logMessages = logMessages;\r\n }\r\n\r\n protected async processDialog(dialog: Puppeteer.Dialog) {\r\n if (this.logMessages) {\r\n console.log(`Dialog message: ${dialog.message()}`);\r\n }\r\n\r\n await dialog.dismiss();\r\n }\r\n}\r\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { Cookie } from 'puppeteer';
2
- import { Plugin } from '../../index';
2
+ import { Plugin } from '../..';
3
3
  export interface ManageCookiesOption {
4
4
  saveLocation: string;
5
5
  mode: 'manual' | 'monitor';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/manage.cookies/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,MAAM,CAAC;IAC1D,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACtD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB;AAED,qBAAa,mBAAoB,SAAQ,MAAM;IAC7C,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,SAAS,CAAkE;IACnF,OAAO,CAAC,KAAK,CAA4C;IACzD,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,OAAO,CAAa;IAE5B,OAAO,CAAC,UAAU,CAAgC;gBAEtC,IAAI,EAAE,mBAAmB;cAgBrB,WAA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@@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ManageCookiesPlugin = void 0;
5
5
  const crypto = require("crypto");
6
- const fs = require("fs");
7
- const index_1 = require("../../index");
6
+ const fs = require("fs/promises");
7
+ const __1 = require("../..");
8
8
  const sleep = (time) => { return new Promise(resolve => { setTimeout(resolve, time); }); };
9
- class ManageCookiesPlugin extends index_1.Plugin {
9
+ class ManageCookiesPlugin extends __1.Plugin {
10
10
  constructor(opts) {
11
11
  super();
12
12
  this.saveLocation = '';
@@ -28,8 +28,12 @@ class ManageCookiesPlugin extends index_1.Plugin {
28
28
  }
29
29
  }
30
30
  async afterLaunch() {
31
- if (fs.existsSync(this.saveLocation)) {
32
- this.allCookies = this.parse(fs.readFileSync(this.saveLocation).toString() || '{}');
31
+ try {
32
+ await fs.access(this.saveLocation);
33
+ this.allCookies = this.parse((await fs.readFile(this.saveLocation)).toString() || '{}');
34
+ }
35
+ catch (_a) {
36
+ null;
33
37
  }
34
38
  void this.watchCookies();
35
39
  }
@@ -88,9 +92,10 @@ class ManageCookiesPlugin extends index_1.Plugin {
88
92
  async saveProfileCookies() {
89
93
  this.allCookies[this.profile] = await this.getCookies();
90
94
  const cookiesString = this.stringify(this.allCookies);
91
- fs.writeFileSync(this.saveLocation, cookiesString);
95
+ await fs.writeFile(this.saveLocation, cookiesString);
92
96
  }
93
97
  async loadProfileCookies() {
98
+ var _a, _b;
94
99
  const page = await this.getFirstPage();
95
100
  if (!page)
96
101
  return;
@@ -98,13 +103,14 @@ class ManageCookiesPlugin extends index_1.Plugin {
98
103
  if (requiresRealPage) {
99
104
  await page.goto('http://www.google.com');
100
105
  }
101
- await page.browser().deleteCookie(...await this.getCookies());
102
- await page.browser().setCookie(...this.allCookies[this.profile] || []);
106
+ await ((_a = this.browser) === null || _a === void 0 ? void 0 : _a.deleteCookie(...await this.getCookies()));
107
+ await ((_b = this.browser) === null || _b === void 0 ? void 0 : _b.setCookie(...this.allCookies[this.profile] || []));
103
108
  if (requiresRealPage) {
104
109
  await page.goBack();
105
110
  }
106
111
  }
107
112
  async clearProfileCookies() {
113
+ var _a;
108
114
  const page = await this.getFirstPage();
109
115
  if (!page)
110
116
  return;
@@ -112,23 +118,24 @@ class ManageCookiesPlugin extends index_1.Plugin {
112
118
  if (requiresRealPage) {
113
119
  await page.goto('http://www.google.com');
114
120
  }
115
- await page.browser().deleteCookie(...this.allCookies[this.profile] || []);
121
+ await ((_a = this.browser) === null || _a === void 0 ? void 0 : _a.deleteCookie(...this.allCookies[this.profile] || []));
116
122
  delete this.allCookies[this.profile];
117
123
  const cookiesString = this.stringify(this.allCookies);
118
- fs.writeFileSync(this.saveLocation, cookiesString);
124
+ await fs.writeFile(this.saveLocation, cookiesString);
119
125
  if (requiresRealPage) {
120
126
  await page.goBack();
121
127
  }
122
128
  }
123
129
  async getCookies() {
130
+ var _a;
124
131
  const page = await this.getFirstPage();
125
132
  if (!page)
126
133
  return [];
127
134
  try {
128
- const cookies = await page.browser().cookies();
135
+ const cookies = await ((_a = this.browser) === null || _a === void 0 ? void 0 : _a.cookies()) || [];
129
136
  return cookies;
130
137
  }
131
- catch (_a) {
138
+ catch (_b) {
132
139
  return [];
133
140
  }
134
141
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/manage.cookies/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;;;AAE3E,iCAAiC;AACjC,yBAAyB;AAGzB,uCAAqC;AAErC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,GAAG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAWnG,MAAa,mBAAoB,SAAQ,cAAM;IAU7C,YAAY,IAAyB;QACnC,KAAK,EAAE,CAAC;QAVF,iBAAY,GAAG,EAAE,CAAC;QAClB,SAAI,GAAG,EAAE,CAAC;QAC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eroenvisser101/636030fe66ea929b63a33f5cb3a711ad\n\nimport * as crypto from 'crypto';\nimport * as fs from 'fs';\nimport type { Cookie } from 'puppeteer';\n\nimport { Plugin } from '../../index';\n\nconst sleep = (time: number) => { return new Promise(resolve => { setTimeout(resolve, time); }); };\n\nexport interface ManageCookiesOption {\n saveLocation: string;\n mode: 'manual' | 'monitor';\n stringify?: (cookies: Record<string, Cookie[]>) => string;\n parse?: (cookies: string) => Record<string, Cookie[]>;\n disableWarning?: boolean;\n profile?: 'string';\n}\n\nexport class ManageCookiesPlugin extends Plugin {\n private saveLocation = '';\n private mode = '';\n private stringify = (cookies: Record<string, Cookie[]>) => JSON.stringify(cookies);\n private parse = (cookies: string) => JSON.parse(cookies);\n private disableWarning = false;\n private profile = 'default';\n\n private allCookies: Record<string, Cookie[]> = {};\n\n constructor(opts: ManageCookiesOption) {\n super();\n\n // Need to find a better typescript way of doing this\n this.saveLocation = opts.saveLocation || this.saveLocation;\n this.mode = opts.mode || this.mode;\n this.stringify = opts.stringify || this.stringify;\n this.parse = opts.parse || this.parse;\n this.disableWarning = opts.disableWarning || this.disableWarning;\n this.profile = opts.profile || this.profile;\n\n if (this.disableWarning !== true) {\n console.warn('Warning: Exposing cookies in an unprotected manner can compromise your security. Add the `disableWarning` flag to remove this message.');\n }\n }\n\n protected async afterLaunch() {\n if (fs.existsSync(this.saveLocation)) {\n this.allCookies = this.parse(fs.readFileSync(this.saveLocation).toString() || '{}');\n }\n\n void this.watchCookies();\n }\n\n protected async afterRestart() {\n void this.watchCookies();\n }\n\n async switchToProfile(profile: string) {\n if (this.isStopped) return;\n\n this.profile = profile;\n\n await this.loadProfileCookies();\n }\n\n async save() {\n if (this.isStopped) return;\n if (this.mode !== 'manual') return;\n\n await this.saveProfileCookies();\n }\n\n async load() {\n if (this.isStopped) return;\n if (this.mode !== 'manual') return;\n\n await this.loadProfileCookies();\n }\n\n async clear() {\n if (this.isStopped) return;\n\n await this.clearProfileCookies();\n }\n\n private async watchCookies() {\n if (this.isStopped) return;\n if (this.mode !== 'monitor') return;\n\n const hash = (x: string) => crypto.createHash('md5').update(x).digest('hex');\n\n let oldProfile = '';\n let oldHash = '';\n\n while (!this.isStopped) {\n const cookies = { [this.profile]: await this.getCookies() };\n const cookiesString = this.stringify(cookies);\n const newHash = hash(cookiesString);\n\n if (oldProfile !== this.profile) {\n oldProfile = this.profile;\n } else if (oldHash !== newHash) {\n oldHash = newHash;\n await this.saveProfileCookies();\n } else {\n await sleep(300);\n }\n }\n }\n\n private async saveProfileCookies() {\n this.allCookies[this.profile] = await this.getCookies();\n\n const cookiesString = this.stringify(this.allCookies);\n fs.writeFileSync(this.saveLocation, cookiesString);\n }\n\n private async loadProfileCookies() {\n const page = await this.getFirstPage();\n if (!page) return;\n\n const requiresRealPage = page.url() === 'about:blank';\n\n if (requiresRealPage) {\n await page.goto('http://www.google.com');\n }\n\n await page.browser().deleteCookie(...await this.getCookies());\n await page.browser().setCookie(...this.allCookies[this.profile] || []);\n\n if (requiresRealPage) {\n await page.goBack();\n }\n }\n\n private async clearProfileCookies() {\n const page = await this.getFirstPage();\n if (!page) return;\n\n const requiresRealPage = page.url() === 'about:blank';\n\n if (requiresRealPage) {\n await page.goto('http://www.google.com');\n }\n\n await page.browser().deleteCookie(...this.allCookies[this.profile] || []);\n delete this.allCookies[this.profile];\n\n const cookiesString = this.stringify(this.allCookies);\n fs.writeFileSync(this.saveLocation, cookiesString);\n\n if (requiresRealPage) {\n await page.goBack();\n }\n }\n\n private async getCookies() {\n const page = await this.getFirstPage();\n if (!page) return [];\n\n try {\n const cookies = await page.browser().cookies();\n\n return cookies;\n } catch {\n return [];\n }\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/manage.cookies/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;;;AAE3E,iCAAiC;AACjC,kCAAkC;AAGlC,6BAA+B;AAE/B,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,GAAG,OAA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EAAE,CAAC;QACtB,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,UAAU;;QACtB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QACvC,IAAI,CAAC,IAAI;YAAE,OAAO,EAAE,CAAC;QAErB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,OAAO,EAAE,CAAA,IAAI,EAAE,CAAC;YAEpD,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,WAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF;AAtJD,kDAsJC","sourcesContent":["// https://gist.github.com/jeroenvisser101/636030fe66ea929b63a33f5cb3a711ad\r\n\r\nimport * as crypto from 'crypto';\r\nimport * as fs from 'fs/promises';\r\nimport type { Cookie } from 'puppeteer';\r\n\r\nimport { Plugin } from '../..';\r\n\r\nconst sleep = (time: number) => { return new Promise(resolve => { setTimeout(resolve, time); }); };\r\n\r\nexport interface ManageCookiesOption {\r\n saveLocation: string;\r\n mode: 'manual' | 'monitor';\r\n stringify?: (cookies: Record<string, Cookie[]>) => string;\r\n parse?: (cookies: string) => Record<string, Cookie[]>;\r\n disableWarning?: boolean;\r\n profile?: 'string';\r\n}\r\n\r\nexport class ManageCookiesPlugin extends Plugin {\r\n private saveLocation = '';\r\n private mode = '';\r\n private stringify = (cookies: Record<string, Cookie[]>) => JSON.stringify(cookies);\r\n private parse = (cookies: string) => JSON.parse(cookies);\r\n private disableWarning = false;\r\n private profile = 'default';\r\n\r\n private allCookies: Record<string, Cookie[]> = {};\r\n\r\n constructor(opts: ManageCookiesOption) {\r\n super();\r\n\r\n // Need to find a better typescript way of doing this\r\n this.saveLocation = opts.saveLocation || this.saveLocation;\r\n this.mode = opts.mode || this.mode;\r\n this.stringify = opts.stringify || this.stringify;\r\n this.parse = opts.parse || this.parse;\r\n this.disableWarning = opts.disableWarning || this.disableWarning;\r\n this.profile = opts.profile || this.profile;\r\n\r\n if (this.disableWarning !== true) {\r\n console.warn('Warning: Exposing cookies in an unprotected manner can compromise your security. Add the `disableWarning` flag to remove this message.');\r\n }\r\n }\r\n\r\n protected async afterLaunch() {\r\n try {\r\n await fs.access(this.saveLocation);\r\n this.allCookies = this.parse((await fs.readFile(this.saveLocation)).toString() || '{}');\r\n } catch { null; }\r\n\r\n void this.watchCookies();\r\n }\r\n\r\n protected async afterRestart() {\r\n void this.watchCookies();\r\n }\r\n\r\n async switchToProfile(profile: string) {\r\n if (this.isStopped) return;\r\n\r\n this.profile = profile;\r\n\r\n await this.loadProfileCookies();\r\n }\r\n\r\n async save() {\r\n if (this.isStopped) return;\r\n if (this.mode !== 'manual') return;\r\n\r\n await this.saveProfileCookies();\r\n }\r\n\r\n async load() {\r\n if (this.isStopped) return;\r\n if (this.mode !== 'manual') return;\r\n\r\n await this.loadProfileCookies();\r\n }\r\n\r\n async clear() {\r\n if (this.isStopped) return;\r\n\r\n await this.clearProfileCookies();\r\n }\r\n\r\n private async watchCookies() {\r\n if (this.isStopped) return;\r\n if (this.mode !== 'monitor') return;\r\n\r\n const hash = (x: string) => crypto.createHash('md5').update(x).digest('hex');\r\n\r\n let oldProfile = '';\r\n let oldHash = '';\r\n\r\n while (!this.isStopped) {\r\n const cookies = { [this.profile]: await this.getCookies() };\r\n const cookiesString = this.stringify(cookies);\r\n const newHash = hash(cookiesString);\r\n\r\n if (oldProfile !== this.profile) {\r\n oldProfile = this.profile;\r\n } else if (oldHash !== newHash) {\r\n oldHash = newHash;\r\n await this.saveProfileCookies();\r\n } else {\r\n await sleep(300);\r\n }\r\n }\r\n }\r\n\r\n private async saveProfileCookies() {\r\n this.allCookies[this.profile] = await this.getCookies();\r\n\r\n const cookiesString = this.stringify(this.allCookies);\r\n await fs.writeFile(this.saveLocation, cookiesString);\r\n }\r\n\r\n private async loadProfileCookies() {\r\n const page = await this.getFirstPage();\r\n if (!page) return;\r\n\r\n const requiresRealPage = page.url() === 'about:blank';\r\n\r\n if (requiresRealPage) {\r\n await page.goto('http://www.google.com');\r\n }\r\n\r\n await this.browser?.deleteCookie(...await this.getCookies());\r\n await this.browser?.setCookie(...this.allCookies[this.profile] || []);\r\n\r\n if (requiresRealPage) {\r\n await page.goBack();\r\n }\r\n }\r\n\r\n private async clearProfileCookies() {\r\n const page = await this.getFirstPage();\r\n if (!page) return;\r\n\r\n const requiresRealPage = page.url() === 'about:blank';\r\n\r\n if (requiresRealPage) {\r\n await page.goto('http://www.google.com');\r\n }\r\n\r\n await this.browser?.deleteCookie(...this.allCookies[this.profile] || []);\r\n delete this.allCookies[this.profile];\r\n\r\n const cookiesString = this.stringify(this.allCookies);\r\n await fs.writeFile(this.saveLocation, cookiesString);\r\n\r\n if (requiresRealPage) {\r\n await page.goBack();\r\n }\r\n }\r\n\r\n private async getCookies() {\r\n const page = await this.getFirstPage();\r\n if (!page) return [];\r\n\r\n try {\r\n const cookies = await this.browser?.cookies() || [];\r\n\r\n return cookies;\r\n } catch {\r\n return [];\r\n }\r\n }\r\n}\r\n"]}
@@ -1,4 +1,4 @@
1
- import { Plugin } from '../../index';
1
+ import { Plugin } from '../..';
2
2
  export interface ManageLocalStorageOption {
3
3
  saveLocation: string;
4
4
  mode: 'manual' | 'monitor';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/manage.localstorage/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC,MAAM,WAAW,wBAAwB;IACvC,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,KAAK,MAAM,CAAC;IACnE,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC/D,cA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CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,SAAS,CAAgF;IACjG,OAAO,CAAC,KAAK,CAAsD;IACnE,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,OAAO,CAAa;IAE5B,OAAO,CAAC,eAAe,CAAoC;gBAE/C,IAAI,EAAE,wBAAwB;cAgB1B,WAAW;cASX,YAAY;IAItB,eAAe,CAAC,OAAO,EAAE,MAAM;IAQ/B,IAAI;IAOJ,IAAI;IAOJ,KAAK;YAMG,iBAAiB;YAyBjB,uBAAuB;YAOvB,uBAAuB;YAIvB,wBAAwB;YAOxB,eAAe;YAoBf,eAAe;CAgB9B;AAED,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC"}
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ManageLocalStoragePlugin = void 0;
5
5
  const crypto = require("crypto");
6
- const fs = require("fs");
7
- const index_1 = require("../../index");
6
+ const fs = require("fs/promises");
7
+ const __1 = require("../..");
8
8
  const sleep = (time) => { return new Promise(resolve => { setTimeout(resolve, time); }); };
9
- class ManageLocalStoragePlugin extends index_1.Plugin {
9
+ class ManageLocalStoragePlugin extends __1.Plugin {
10
10
  constructor(opts) {
11
11
  super();
12
12
  this.saveLocation = '';
@@ -28,8 +28,12 @@ class ManageLocalStoragePlugin extends index_1.Plugin {
28
28
  }
29
29
  }
30
30
  async afterLaunch() {
31
- if (fs.existsSync(this.saveLocation)) {
32
- this.allLocalStorage = this.parse(fs.readFileSync(this.saveLocation).toString() || '{}');
31
+ try {
32
+ await fs.access(this.saveLocation);
33
+ this.allLocalStorage = this.parse((await fs.readFile(this.saveLocation)).toString() || '{}');
34
+ }
35
+ catch (_a) {
36
+ null;
33
37
  }
34
38
  void this.watchLocalStorage();
35
39
  }
@@ -88,7 +92,7 @@ class ManageLocalStoragePlugin extends index_1.Plugin {
88
92
  async saveProfileLocalStorage() {
89
93
  this.allLocalStorage[this.profile] = await this.getLocalStorage();
90
94
  const localStorageString = this.stringify(this.allLocalStorage);
91
- fs.writeFileSync(this.saveLocation, localStorageString);
95
+ await fs.writeFile(this.saveLocation, localStorageString);
92
96
  }
93
97
  async loadProfileLocalStorage() {
94
98
  await this.setLocalStorage(this.allLocalStorage[this.profile] || {});
@@ -96,7 +100,7 @@ class ManageLocalStoragePlugin extends index_1.Plugin {
96
100
  async clearProfileLocalStorage() {
97
101
  delete this.allLocalStorage[this.profile];
98
102
  const localStorageString = this.stringify(this.allLocalStorage);
99
- fs.writeFileSync(this.saveLocation, localStorageString);
103
+ await fs.writeFile(this.saveLocation, localStorageString);
100
104
  }
101
105
  async setLocalStorage(allLocalStorage) {
102
106
  if (!this.browser)
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/manage.localstorage/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;;;AAE3E,iCAAiC;AACjC,yBAAyB;AAEzB,uCAAqC;AAErC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,GAAG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAWnG,MAAa,wBAAyB,SAAQ,cAAM;IAUlD,YAAY,IAA8B;QACxC,KAAK,EAAE,CAAC;QAVF,iBAAY,GAAG,EAAE,CAAC;QAClB,SAAI,GAAG,EAAE,CAAC;QACV,cAAS,GAAG,CAAC,YAA0C,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QACzF,UAAK,GAAG,CAAC,YAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAC3D,mBAAc,GAAG,KAAK,CAAC;QACvB,YAAO,GAAG,SAAS,CAAC;QAEpB,oBAAe,GAAiC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O,eAAe,CAAC;IACzB,CAAC;CACF;AAjJD,4DAiJC","sourcesContent":["// https://gist.github.com/jeroenvisser101/636030fe66ea929b63a33f5cb3a711ad\n\nimport * as crypto from 'crypto';\nimport * as fs from 'fs';\n\nimport { Plugin } from '../../index';\n\nconst sleep = (time: number) => { return new Promise(resolve => { setTimeout(resolve, time); }); };\n\nexport interface ManageLocalStorageOption {\n saveLocation: string;\n mode: 'manual' | 'monitor';\n stringify?: (localStorage: Record<string, LocalStorage>) => string;\n parse?: (localStorage: string) => Record<string, LocalStorage>;\n disableWarning?: boolean;\n profile?: 'string';\n}\n\nexport class ManageLocalStoragePlugin extends Plugin {\n private saveLocation = '';\n private mode = '';\n private stringify = (localStorage: Record<string, LocalStorage>) => JSON.stringify(localStorage);\n private parse = (localStorage: string) => JSON.parse(localStorage);\n private disableWarning = false;\n private profile = 'default';\n\n private allLocalStorage: Record<string, LocalStorage> = {};\n\n constructor(opts: ManageLocalStorageOption) {\n super();\n\n // Need to find a better typescript way of doing this\n this.saveLocation = opts.saveLocation || this.saveLocation;\n this.mode = opts.mode || this.mode;\n this.stringify = opts.stringify || this.stringify;\n this.parse = opts.parse || this.parse;\n this.disableWarning = opts.disableWarning || this.disableWarning;\n this.profile = opts.profile || this.profile;\n\n if (this.disableWarning !== true) {\n console.warn('Warning: Exposing local storage in an unprotected manner can compromise your security. Add the `disableWarning` flag to remove this message.');\n }\n }\n\n protected async afterLaunch() {\n if (fs.existsSync(this.saveLocation)) {\n this.allLocalStorage = this.parse(fs.readFileSync(this.saveLocation).toString() || '{}');\n }\n\n void this.watchLocalStorage();\n }\n\n protected async afterRestart() {\n void this.watchLocalStorage();\n }\n\n async switchToProfile(profile: string) {\n if (this.isStopped) return;\n\n this.profile = profile;\n\n await this.loadProfileLocalStorage();\n }\n\n async save() {\n if (this.isStopped) return;\n if (this.mode !== 'manual') return;\n\n await this.saveProfileLocalStorage();\n }\n\n async load() {\n if (this.isStopped) return;\n if (this.mode !== 'manual') return;\n\n await this.loadProfileLocalStorage();\n }\n\n async clear() {\n if (this.isStopped) return;\n\n await this.clearProfileLocalStorage();\n }\n\n private async watchLocalStorage() {\n if (this.isStopped) return;\n if (this.mode !== 'monitor') return;\n\n const hash = (x: string) => crypto.createHash('md5').update(x).digest('hex');\n\n let oldProfile = '';\n let oldHash = '';\n\n while (!this.isStopped) {\n const localStorage = { [this.profile]: await this.getLocalStorage() };\n const localStorageString = this.stringify(localStorage);\n const newHash = hash(localStorageString);\n\n if (oldProfile !== this.profile) {\n oldProfile = this.profile;\n } else if (oldHash !== newHash) {\n oldHash = newHash;\n await this.saveProfileLocalStorage();\n } else {\n await sleep(300);\n }\n }\n }\n\n private async saveProfileLocalStorage() {\n this.allLocalStorage[this.profile] = await this.getLocalStorage();\n\n const localStorageString = this.stringify(this.allLocalStorage);\n fs.writeFileSync(this.saveLocation, localStorageString);\n }\n\n private async loadProfileLocalStorage() {\n await this.setLocalStorage(this.allLocalStorage[this.profile] || {});\n }\n\n private async clearProfileLocalStorage() {\n delete this.allLocalStorage[this.profile];\n\n const localStorageString = this.stringify(this.allLocalStorage);\n fs.writeFileSync(this.saveLocation, localStorageString);\n }\n\n private async setLocalStorage(allLocalStorage: LocalStorage) {\n if (!this.browser) return;\n\n const pages = await this.browser.pages();\n const activePages = pages.filter(x => x.url() !== 'about:blank');\n\n for (const page of activePages) {\n const origin = await page.evaluate(() => window.origin);\n\n await page.evaluate(originLocalStorage => {\n const keys = Object.keys(originLocalStorage);\n localStorage.clear();\n\n for (let i = 0; i < Object.keys(localStorage).length; i++) {\n localStorage.setItem(keys[i], originLocalStorage[keys[i]]);\n }\n }, allLocalStorage[origin] || {});\n }\n }\n\n private async getLocalStorage() {\n if (!this.browser) return {};\n\n const allLocalStorage: LocalStorage = {};\n\n const pages = await this.browser.pages();\n const activePages = pages.filter(x => x.url() !== 'about:blank');\n\n for (const page of activePages) {\n const originLocalStorage = await page.evaluate(() => ({ [window.origin]: { ...localStorage } })) as LocalStorage;\n\n Object.assign(allLocalStorage, originLocalStorage);\n }\n\n return allLocalStorage;\n }\n}\n\ntype LocalStorage = Record<string, Record<string, string>>;\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/manage.localstorage/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;;;AAE3E,iCAAiC;AACjC,kCAAkC;AAElC,6BAA+B;AAE/B,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,GAAG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAWnG,MAAa,wBAAyB,SAAQ,UAAM;IAUlD,YAAY,IAA8B;QACxC,KAAK,EAAE,CAAC;QAVF,iBAAY,GAAG,EAAE,CAAC;QAClB,SAAI,GAAG,EAAE,CAAC;QACV,cAAS,GAAG,CAAC,YAA0C,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QACzF,UAAK,GAAG,CAAC,YAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAC3D,mBAAc,GAAG,KAAK,CAAC;QACvB,YAAO,GAAG,SAAS,CAAC;QAEpB,oBAAe,GAAiC,EAAE,CAAC;QAKzD,qDAAqD;QACrD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC;QAC3D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;QAClD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;QACtC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,cA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IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBAC1D,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7D,CAAC;YACH,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,eAAe;QAC3B,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,CAAC;QAE7B,MAAM,eAAe,GAAiB,EAAE,CAAC;QAEzC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACzC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,aAAa,CAAC,CAAC;QAEjE,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;YAC/B,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,YAAY,EAAE,EAAE,CAAC,CAAiB,CAAC;YAEjH,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AAlJD,4DAkJC","sourcesContent":["// https://gist.github.com/jeroenvisser101/636030fe66ea929b63a33f5cb3a711ad\r\n\r\nimport * as crypto from 'crypto';\r\nimport * as fs from 'fs/promises';\r\n\r\nimport { Plugin } from '../..';\r\n\r\nconst sleep = (time: number) => { return new Promise(resolve => { setTimeout(resolve, time); }); };\r\n\r\nexport interface ManageLocalStorageOption {\r\n saveLocation: string;\r\n mode: 'manual' | 'monitor';\r\n stringify?: (localStorage: Record<string, LocalStorage>) => string;\r\n parse?: (localStorage: string) => Record<string, LocalStorage>;\r\n disableWarning?: boolean;\r\n profile?: 'string';\r\n}\r\n\r\nexport class ManageLocalStoragePlugin extends Plugin {\r\n private saveLocation = '';\r\n private mode = '';\r\n private stringify = (localStorage: Record<string, LocalStorage>) => JSON.stringify(localStorage);\r\n private parse = (localStorage: string) => JSON.parse(localStorage);\r\n private disableWarning = false;\r\n private profile = 'default';\r\n\r\n private allLocalStorage: Record<string, LocalStorage> = {};\r\n\r\n constructor(opts: ManageLocalStorageOption) {\r\n super();\r\n\r\n // Need to find a better typescript way of doing this\r\n this.saveLocation = opts.saveLocation || this.saveLocation;\r\n this.mode = opts.mode || this.mode;\r\n this.stringify = opts.stringify || this.stringify;\r\n this.parse = opts.parse || this.parse;\r\n this.disableWarning = opts.disableWarning || this.disableWarning;\r\n this.profile = opts.profile || this.profile;\r\n\r\n if (this.disableWarning !== true) {\r\n console.warn('Warning: Exposing local storage in an unprotected manner can compromise your security. Add the `disableWarning` flag to remove this message.');\r\n }\r\n }\r\n\r\n protected async afterLaunch() {\r\n try {\r\n await fs.access(this.saveLocation);\r\n this.allLocalStorage = this.parse((await fs.readFile(this.saveLocation)).toString() || '{}');\r\n } catch { null; }\r\n\r\n void this.watchLocalStorage();\r\n }\r\n\r\n protected async afterRestart() {\r\n void this.watchLocalStorage();\r\n }\r\n\r\n async switchToProfile(profile: string) {\r\n if (this.isStopped) return;\r\n\r\n this.profile = profile;\r\n\r\n await this.loadProfileLocalStorage();\r\n }\r\n\r\n async save() {\r\n if (this.isStopped) return;\r\n if (this.mode !== 'manual') return;\r\n\r\n await this.saveProfileLocalStorage();\r\n }\r\n\r\n async load() {\r\n if (this.isStopped) return;\r\n if (this.mode !== 'manual') return;\r\n\r\n await this.loadProfileLocalStorage();\r\n }\r\n\r\n async clear() {\r\n if (this.isStopped) return;\r\n\r\n await this.clearProfileLocalStorage();\r\n }\r\n\r\n private async watchLocalStorage() {\r\n if (this.isStopped) return;\r\n if (this.mode !== 'monitor') return;\r\n\r\n const hash = (x: string) => crypto.createHash('md5').update(x).digest('hex');\r\n\r\n let oldProfile = '';\r\n let oldHash = '';\r\n\r\n while (!this.isStopped) {\r\n const localStorage = { [this.profile]: await this.getLocalStorage() };\r\n const localStorageString = this.stringify(localStorage);\r\n const newHash = hash(localStorageString);\r\n\r\n if (oldProfile !== this.profile) {\r\n oldProfile = this.profile;\r\n } else if (oldHash !== newHash) {\r\n oldHash = newHash;\r\n await this.saveProfileLocalStorage();\r\n } else {\r\n await sleep(300);\r\n }\r\n }\r\n }\r\n\r\n private async saveProfileLocalStorage() {\r\n this.allLocalStorage[this.profile] = await this.getLocalStorage();\r\n\r\n const localStorageString = this.stringify(this.allLocalStorage);\r\n await fs.writeFile(this.saveLocation, localStorageString);\r\n }\r\n\r\n private async loadProfileLocalStorage() {\r\n await this.setLocalStorage(this.allLocalStorage[this.profile] || {});\r\n }\r\n\r\n private async clearProfileLocalStorage() {\r\n delete this.allLocalStorage[this.profile];\r\n\r\n const localStorageString = this.stringify(this.allLocalStorage);\r\n await fs.writeFile(this.saveLocation, localStorageString);\r\n }\r\n\r\n private async setLocalStorage(allLocalStorage: LocalStorage) {\r\n if (!this.browser) return;\r\n\r\n const pages = await this.browser.pages();\r\n const activePages = pages.filter(x => x.url() !== 'about:blank');\r\n\r\n for (const page of activePages) {\r\n const origin = await page.evaluate(() => window.origin);\r\n\r\n await page.evaluate(originLocalStorage => {\r\n const keys = Object.keys(originLocalStorage);\r\n localStorage.clear();\r\n\r\n for (let i = 0; i < Object.keys(localStorage).length; i++) {\r\n localStorage.setItem(keys[i], originLocalStorage[keys[i]]);\r\n }\r\n }, allLocalStorage[origin] || {});\r\n }\r\n }\r\n\r\n private async getLocalStorage() {\r\n if (!this.browser) return {};\r\n\r\n const allLocalStorage: LocalStorage = {};\r\n\r\n const pages = await this.browser.pages();\r\n const activePages = pages.filter(x => x.url() !== 'about:blank');\r\n\r\n for (const page of activePages) {\r\n const originLocalStorage = await page.evaluate(() => ({ [window.origin]: { ...localStorage } })) as LocalStorage;\r\n\r\n Object.assign(allLocalStorage, originLocalStorage);\r\n }\r\n\r\n return allLocalStorage;\r\n }\r\n}\r\n\r\ntype LocalStorage = Record<string, Record<string, string>>;\r\n"]}
@@ -1,6 +1,6 @@
1
1
  import * as Puppeteer from 'puppeteer';
2
- import { Plugin } from '../../index';
3
- import { AvoidDetectionPlugin } from './../avoid.detection/index';
2
+ import { Plugin } from '../..';
3
+ import { AvoidDetectionPlugin } from './../avoid.detection';
4
4
  export declare class SolveRecaptchaPlugin extends Plugin {
5
5
  dependencies: AvoidDetectionPlugin[];
6
6
  witAiAccessToken?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/solve.recaptcha/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAGvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAMlE,qBAAa,oBAAqB,SAAQ,MAAM;IAC9C,YAAY,yBAAgC;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAC;gBAEd,gBAAgB,EAAE,MAAM;IAK9B,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM;IAKrD,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI;IAK/B,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI;CAqE1C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/solve.recaptcha/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAGvC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAM5D,qBAAa,oBAAqB,SAAQ,MAAM;IAC9C,YAAY,yBAAgC;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAC;gBAEd,gBAAgB,EAAE,MAAM;IAK9B,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM;IAKrD,UAAU,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI;IAK/B,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI;CAqE1C"}
@@ -4,15 +4,15 @@ exports.SolveRecaptchaPlugin = void 0;
4
4
  const axios_1 = require("axios");
5
5
  const path = require("path");
6
6
  const ghost_cursor_1 = require("ghost-cursor");
7
- const index_1 = require("../../index");
8
- const index_2 = require("./../avoid.detection/index");
7
+ const __1 = require("../..");
8
+ const avoid_detection_1 = require("./../avoid.detection");
9
9
  // eslint-disable-next-line @typescript-eslint/no-require-imports
10
10
  const injection = require(path.resolve(`${__dirname}/injections`) + '/utils.js');
11
11
  const randomBetween = (min, max) => Math.floor(Math.random() * (max - min)) + min;
12
- class SolveRecaptchaPlugin extends index_1.Plugin {
12
+ class SolveRecaptchaPlugin extends __1.Plugin {
13
13
  constructor(witAiAccessToken) {
14
14
  super();
15
- this.dependencies = [new index_2.AvoidDetectionPlugin()];
15
+ this.dependencies = [new avoid_detection_1.AvoidDetectionPlugin()];
16
16
  this.witAiAccessToken = witAiAccessToken;
17
17
  }
18
18
  async waitForCaptcha(page, timeout) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/solve.recaptcha/index.ts"],"names":[],"mappings":";;;AAAA,iCAA0B;AAC1B,6BAA6B;AAE7B,+CAA4C;AAE5C,uCAAqC;AACrC,sDAAkE;AAElE,iEAAiE;AACjE,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,SAAS,aAAa,CAAC,GAAG,WAAW,CAAC,CAAC;AACjF,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,GAAW,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IAAI,CAAC,IAAI,CAAC,CAAA,CAAC;gBAErC,MAAM,YAAY,CAAC,WAAW,EAAE,0BAA0B,CAAC,CAAC;gBAE5D,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACN,MAAM,YAAY,CAAC,WAAW,EAAE,0BAA0B,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAxFD,oDAwFC;AAED,SAAS,KAAK,CAAC,OAAe;IAC5B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import axios from 'axios';\nimport * as path from 'path';\nimport * as Puppeteer from 'puppeteer';\nimport { createCursor } from 'ghost-cursor';\n\nimport { Plugin } from '../../index';\nimport { AvoidDetectionPlugin } from './../avoid.detection/index';\n\n// eslint-disable-next-line @typescript-eslint/no-require-imports\nconst injection = require(path.resolve(`${__dirname}/injections`) + '/utils.js');\nconst randomBetween = (min: number, max: number) => Math.floor(Math.random() * (max - min)) + min;\n\nexport class SolveRecaptchaPlugin extends Plugin {\n dependencies = [new AvoidDetectionPlugin()];\n witAiAccessToken?: string;\n\n constructor(witAiAccessToken: string) {\n super();\n this.witAiAccessToken = witAiAccessToken;\n }\n\n async waitForCaptcha(page: Puppeteer.Page, timeout?: number) {\n return page.waitForFunction(() => !!document.querySelector<HTMLIFrameElement>('iframe[src*=\"api2/anchor\"]') &&\n !!document.querySelector<HTMLIFrameElement>('iframe[src*=\"api2/bframe\"]'), { timeout });\n }\n\n async hasCaptcha(page: Puppeteer.Page) {\n return page.evaluate(() => !!document.querySelector<HTMLIFrameElement>('iframe[src*=\"api2/anchor\"]') &&\n !!document.querySelector<HTMLIFrameElement>('iframe[src*=\"api2/bframe\"]'));\n }\n\n async solveRecaptcha(page: Puppeteer.Page) {\n if (this.isStopped) return;\n if (!this.witAiAccessToken) return;\n if (!(await this.hasCaptcha(page))) return;\n\n const anchorFrame = page.frames().find(x => x.url().includes('api2/anchor'));\n if (!anchorFrame) return;\n\n const cursor = createCursor(page);\n\n async function waitForSelector(iframe: Puppeteer.Frame, selector: string) {\n await iframe.waitForFunction((_selector: string) => document.querySelector(_selector), {}, selector);\n }\n\n async function findAndClick(iframe: Puppeteer.Frame, selector: string) {\n await waitForSelector(iframe, selector);\n\n const element = await iframe.$(selector);\n if (!element) return;\n\n await sleep(randomBetween(1 * 1000, 3 * 1000));\n await cursor.click(element);\n }\n\n let numTriesLeft = 5;\n async function isFinished() {\n if (--numTriesLeft === 0) return true;\n return anchorFrame?.evaluate(() => !!document.querySelector('.recaptcha-checkbox-checked'));\n }\n\n await findAndClick(anchorFrame, '#recaptcha-anchor');\n\n const bframeFrame = page.frames().find(x => x.url().includes('api2/bframe'));\n if (!bframeFrame) return;\n\n await findAndClick(bframeFrame, '.rc-button-audio');\n\n while (!(await isFinished())) {\n await waitForSelector(bframeFrame, '.rc-audiochallenge-tdownload-link');\n\n const audioUrl = await bframeFrame.evaluate(async () => document.querySelector<HTMLLinkElement>('.rc-audiochallenge-tdownload-link')?.href);\n if (!audioUrl) return;\n\n const audioArray = await bframeFrame.evaluate(injection, audioUrl);\n if (!audioArray) return;\n\n const audioBuffer = Buffer.from(new Int8Array(audioArray));\n\n const response = await axios.post<any>('https://api.wit.ai/speech?v=20220527', audioBuffer, {\n headers: {\n Authorization: `Bearer ${this.witAiAccessToken}`,\n 'Content-Type': 'audio/wav',\n },\n });\n\n const data = typeof response.data === 'string' ? JSON.parse(response.data.split('\\r\\n').slice(-1)[0] || '{}') : response.data;\n\n if (data?.text) {\n const responseInput = await bframeFrame.$('#audio-response');\n await responseInput?.type(data.text);\n\n await findAndClick(bframeFrame, '#recaptcha-verify-button');\n\n await sleep(1000);\n } else {\n await findAndClick(bframeFrame, '#recaptcha-reload-button');\n }\n }\n }\n}\n\nfunction sleep(timeout: number) {\n return new Promise(resolve => setTimeout(resolve, timeout));\n}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,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAE9H,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAAE,CAAC;gBACf,MAAM,aAAa,GAAG,MAAM,WAAW,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;gBAC7D,MAAM,CAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,CAAC;gBAErC,MAAM,YAAY,CAAC,WAAW,EAAE,0BAA0B,CAAC,CAAC;gBAE5D,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;YACpB,CAAC;iBAAM,CAAC;gBACN,MAAM,YAAY,CAAC,WAAW,EAAE,0BAA0B,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAxFD,oDAwFC;AAED,SAAS,KAAK,CAAC,OAAe;IAC5B,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["import axios from 'axios';\r\nimport * as path from 'path';\r\nimport * as Puppeteer from 'puppeteer';\r\nimport { createCursor } from 'ghost-cursor';\r\n\r\nimport { Plugin } from '../..';\r\nimport { AvoidDetectionPlugin } from './../avoid.detection';\r\n\r\n// eslint-disable-next-line @typescript-eslint/no-require-imports\r\nconst injection = require(path.resolve(`${__dirname}/injections`) + '/utils.js');\r\nconst randomBetween = (min: number, max: number) => Math.floor(Math.random() * (max - min)) + min;\r\n\r\nexport class SolveRecaptchaPlugin extends Plugin {\r\n dependencies = [new AvoidDetectionPlugin()];\r\n witAiAccessToken?: string;\r\n\r\n constructor(witAiAccessToken: string) {\r\n super();\r\n this.witAiAccessToken = witAiAccessToken;\r\n }\r\n\r\n async waitForCaptcha(page: Puppeteer.Page, timeout?: number) {\r\n return page.waitForFunction(() => !!document.querySelector<HTMLIFrameElement>('iframe[src*=\"api2/anchor\"]') &&\r\n !!document.querySelector<HTMLIFrameElement>('iframe[src*=\"api2/bframe\"]'), { timeout });\r\n }\r\n\r\n async hasCaptcha(page: Puppeteer.Page) {\r\n return page.evaluate(() => !!document.querySelector<HTMLIFrameElement>('iframe[src*=\"api2/anchor\"]') &&\r\n !!document.querySelector<HTMLIFrameElement>('iframe[src*=\"api2/bframe\"]'));\r\n }\r\n\r\n async solveRecaptcha(page: Puppeteer.Page) {\r\n if (this.isStopped) return;\r\n if (!this.witAiAccessToken) return;\r\n if (!(await this.hasCaptcha(page))) return;\r\n\r\n const anchorFrame = page.frames().find(x => x.url().includes('api2/anchor'));\r\n if (!anchorFrame) return;\r\n\r\n const cursor = createCursor(page);\r\n\r\n async function waitForSelector(iframe: Puppeteer.Frame, selector: string) {\r\n await iframe.waitForFunction((_selector: string) => document.querySelector(_selector), {}, selector);\r\n }\r\n\r\n async function findAndClick(iframe: Puppeteer.Frame, selector: string) {\r\n await waitForSelector(iframe, selector);\r\n\r\n const element = await iframe.$(selector);\r\n if (!element) return;\r\n\r\n await sleep(randomBetween(1 * 1000, 3 * 1000));\r\n await cursor.click(element);\r\n }\r\n\r\n let numTriesLeft = 5;\r\n async function isFinished() {\r\n if (--numTriesLeft === 0) return true;\r\n return anchorFrame?.evaluate(() => !!document.querySelector('.recaptcha-checkbox-checked'));\r\n }\r\n\r\n await findAndClick(anchorFrame, '#recaptcha-anchor');\r\n\r\n const bframeFrame = page.frames().find(x => x.url().includes('api2/bframe'));\r\n if (!bframeFrame) return;\r\n\r\n await findAndClick(bframeFrame, '.rc-button-audio');\r\n\r\n while (!(await isFinished())) {\r\n await waitForSelector(bframeFrame, '.rc-audiochallenge-tdownload-link');\r\n\r\n const audioUrl = await bframeFrame.evaluate(async () => document.querySelector<HTMLLinkElement>('.rc-audiochallenge-tdownload-link')?.href);\r\n if (!audioUrl) return;\r\n\r\n const audioArray = await bframeFrame.evaluate(injection, audioUrl);\r\n if (!audioArray) return;\r\n\r\n const audioBuffer = Buffer.from(new Int8Array(audioArray));\r\n\r\n const response = await axios.post<any>('https://api.wit.ai/speech?v=20220527', audioBuffer, {\r\n headers: {\r\n Authorization: `Bearer ${this.witAiAccessToken}`,\r\n 'Content-Type': 'audio/wav',\r\n },\r\n });\r\n\r\n const data = typeof response.data === 'string' ? JSON.parse(response.data.split('\\r\\n').slice(-1)[0] || '{}') : response.data;\r\n\r\n if (data?.text) {\r\n const responseInput = await bframeFrame.$('#audio-response');\r\n await responseInput?.type(data.text);\r\n\r\n await findAndClick(bframeFrame, '#recaptcha-verify-button');\r\n\r\n await sleep(1000);\r\n } else {\r\n await findAndClick(bframeFrame, '#recaptcha-reload-button');\r\n }\r\n }\r\n }\r\n}\r\n\r\nfunction sleep(timeout: number) {\r\n return new Promise(resolve => setTimeout(resolve, timeout));\r\n}\r\n"]}