puppeteer-pro 2.5.2 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -88
- package/index.d.ts +1 -29
- package/index.d.ts.map +1 -1
- package/index.js +3 -157
- package/index.js.map +1 -1
- package/package.json +10 -12
- package/plugins/anonymize.user.agent/index.d.ts +2 -1
- package/plugins/anonymize.user.agent/index.d.ts.map +1 -1
- package/plugins/anonymize.user.agent/index.js +4 -4
- package/plugins/anonymize.user.agent/index.js.map +1 -1
- package/plugins/avoid.detection/index.d.ts +2 -1
- package/plugins/avoid.detection/index.d.ts.map +1 -1
- package/plugins/avoid.detection/index.js +1 -1
- package/plugins/avoid.detection/index.js.map +1 -1
- package/plugins/block.resources/index.d.ts +1 -1
- package/plugins/block.resources/index.d.ts.map +1 -1
- package/plugins/block.resources/index.js +1 -1
- package/plugins/block.resources/index.js.map +1 -1
- package/plugins/disable.dialogs/index.d.ts +1 -1
- package/plugins/disable.dialogs/index.d.ts.map +1 -1
- package/plugins/disable.dialogs/index.js +1 -1
- package/plugins/disable.dialogs/index.js.map +1 -1
- package/plugins/index.d.ts +30 -0
- package/plugins/index.d.ts.map +1 -0
- package/plugins/index.js +159 -0
- package/plugins/index.js.map +1 -0
- package/plugins/manage.cookies/index.d.ts +1 -1
- package/plugins/manage.cookies/index.d.ts.map +1 -1
- package/plugins/manage.cookies/index.js +4 -3
- package/plugins/manage.cookies/index.js.map +1 -1
- package/plugins/manage.localstorage/index.d.ts +1 -1
- package/plugins/manage.localstorage/index.d.ts.map +1 -1
- package/plugins/manage.localstorage/index.js +4 -3
- package/plugins/manage.localstorage/index.js.map +1 -1
- package/plugins/shared.d.ts +7 -0
- package/plugins/shared.d.ts.map +1 -0
- package/plugins/shared.js +23 -0
- package/plugins/shared.js.map +1 -0
- package/plugins/solve.recaptchas/index.d.ts +2 -1
- package/plugins/solve.recaptchas/index.d.ts.map +1 -1
- package/plugins/solve.recaptchas/index.js +3 -2
- package/plugins/solve.recaptchas/index.js.map +1 -1
- package/plugins/solve.recaptchas/injections/utils.js +144 -144
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AvoidDetectionPlugin = void 0;
|
|
4
4
|
const fingerprint_injector_1 = require("fingerprint-injector");
|
|
5
|
-
const __1 = require("
|
|
5
|
+
const __1 = require("..");
|
|
6
6
|
class AvoidDetectionPlugin extends __1.Plugin {
|
|
7
7
|
constructor(fingerprintOptions) {
|
|
8
8
|
super();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/avoid.detection/index.ts"],"names":[],"mappings":";;;AAAA,+DAAuD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/avoid.detection/index.ts"],"names":[],"mappings":";;;AAAA,+DAAuD;AAGvD,0BAA4B;AAI5B,MAAa,oBAAqB,SAAQ,UAAM;IAG9C,YAAY,kBAAgD;QAC1D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;IAC/C,CAAC;IAES,KAAK,CAAC,WAAW,CAAC,OAAiC;QAC3D,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;QACjC,OAAO,CAAC,OAAO,GAAG,KAAK,IAAmB,EAAE;YAC1C,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,EAAE;gBACvB,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;oBACpC,OAAO,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;gBACjC,CAAC;qBAAM,CAAC;oBACN,OAAO,IAAA,sCAAe,EAAC,EAAE,OAAO,EAAE,QAAQ,EAAa,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBACpF,CAAC;YACH,CAAC,CAAC,EAAE,CAAC;YAEL,OAAO,IAAI,CAAC;QACd,CAAC,CAAC;IACJ,CAAC;CACF;AAtBD,oDAsBC","sourcesContent":["import { newInjectedPage } from 'fingerprint-injector';\n\nimport type { Browser, BrowserContext, Page } from '../..';\nimport { Plugin } from '..';\n\ntype FingerprintGeneratorOptions = Parameters<typeof newInjectedPage>[1];\n\nexport class AvoidDetectionPlugin extends Plugin {\n fingerprintOptions?: FingerprintGeneratorOptions;\n\n constructor(fingerprintOptions?: FingerprintGeneratorOptions) {\n super();\n this.fingerprintOptions = fingerprintOptions;\n }\n\n protected async afterLaunch(browser: Browser | BrowserContext) {\n const _newPage = browser.newPage;\n browser.newPage = async (): Promise<Page> => {\n const page = await (() => {\n if (this.isStopped || !this.browser) {\n return _newPage.apply(browser);\n } else {\n return newInjectedPage({ newPage: _newPage } as Browser, this.fingerprintOptions);\n }\n })();\n\n return page;\n };\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Puppeteer from 'puppeteer';
|
|
2
|
-
import { Plugin } from '
|
|
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,
|
|
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,IAAI,CAAC;AAE5B,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,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BlockResourcesPlugin = void 0;
|
|
4
|
-
const __1 = require("
|
|
4
|
+
const __1 = require("..");
|
|
5
5
|
class BlockResourcesPlugin extends __1.Plugin {
|
|
6
6
|
constructor(resources = []) {
|
|
7
7
|
super();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/block.resources/index.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/block.resources/index.ts"],"names":[],"mappings":";;;AAEA,0BAA4B;AAG5B,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';\n\nimport { Plugin } from '..';\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 +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,
|
|
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,IAAI,CAAC;AAE5B,qBAAa,oBAAqB,SAAQ,MAAM;IAC9C,WAAW,EAAE,OAAO,CAAC;gBAET,WAAW,UAAQ;cAMf,aAAa,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM;CAOvD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DisableDialogsPlugin = void 0;
|
|
4
|
-
const __1 = require("
|
|
4
|
+
const __1 = require("..");
|
|
5
5
|
class DisableDialogsPlugin extends __1.Plugin {
|
|
6
6
|
constructor(logMessages = false) {
|
|
7
7
|
super();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/disable.dialogs/index.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/disable.dialogs/index.ts"],"names":[],"mappings":";;;AAEA,0BAA4B;AAE5B,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';\n\nimport { Plugin } from '..';\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"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as Puppeteer from 'puppeteer';
|
|
2
|
+
import type { Browser, BrowserContext, Page } from '..';
|
|
3
|
+
import { Dialog } from './shared';
|
|
4
|
+
export declare class Plugin {
|
|
5
|
+
protected browser: Browser | BrowserContext | null;
|
|
6
|
+
private initialized;
|
|
7
|
+
private startCounter;
|
|
8
|
+
protected dependencies: Plugin[];
|
|
9
|
+
protected requiresInterception: boolean;
|
|
10
|
+
get isInitialized(): boolean;
|
|
11
|
+
get isStopped(): boolean;
|
|
12
|
+
addDependency(plugin: Plugin): Promise<void>;
|
|
13
|
+
init(browser: Browser | BrowserContext): Promise<void>;
|
|
14
|
+
protected afterLaunch(_browser: Browser | BrowserContext): Promise<void>;
|
|
15
|
+
protected onClose(): Promise<void>;
|
|
16
|
+
protected onTargetCreated(target: Puppeteer.Target): Promise<void>;
|
|
17
|
+
protected onPageCreated(_page: Page): Promise<void>;
|
|
18
|
+
protected onRequest(request: Puppeteer.HTTPRequest): Promise<void>;
|
|
19
|
+
protected processRequest(_request: Puppeteer.HTTPRequest): Promise<void>;
|
|
20
|
+
protected onDialog(dialog: Dialog): Promise<void>;
|
|
21
|
+
protected processDialog(_dialog: Dialog): Promise<void>;
|
|
22
|
+
protected beforeRestart(): Promise<void>;
|
|
23
|
+
restart(): Promise<void>;
|
|
24
|
+
protected afterRestart(): Promise<void>;
|
|
25
|
+
protected beforeStop(): Promise<void>;
|
|
26
|
+
stop(): Promise<void>;
|
|
27
|
+
protected afterStop(): Promise<void>;
|
|
28
|
+
protected getFirstPage(): Promise<Puppeteer.Page | null>;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AACxD,OAAO,EAAE,MAAM,EAAW,MAAM,UAAU,CAAC;AAE3C,qBAAa,MAAM;IACjB,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAAQ;IAC1D,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,OAAO,GAAG,cAAc;cA6B5B,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,cAAc;cAC9C,OAAO;cAEP,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM;cAqExC,aAAa,CAAC,KAAK,EAAE,IAAI;cAEzB,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,WAAW;cAQxC,cAAc,CAAC,QAAQ,EAAE,SAAS,CAAC,WAAW;cAE9C,QAAQ,CAAC,MAAM,EAAE,MAAM;cAavB,aAAa,CAAC,OAAO,EAAE,MAAM;cAE7B,aAAa;IACvB,OAAO;cAWG,YAAY;cAEZ,UAAU;IACpB,IAAI;cAmBM,SAAS;cAET,YAAY;CAS7B"}
|
package/plugins/index.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable prefer-rest-params */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Plugin = void 0;
|
|
5
|
+
const shared_1 = require("./shared");
|
|
6
|
+
class Plugin {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.browser = null;
|
|
9
|
+
this.initialized = false;
|
|
10
|
+
this.startCounter = 0;
|
|
11
|
+
this.dependencies = [];
|
|
12
|
+
this.requiresInterception = false;
|
|
13
|
+
}
|
|
14
|
+
get isInitialized() { return this.initialized; }
|
|
15
|
+
get isStopped() { return this.startCounter === 0; }
|
|
16
|
+
async addDependency(plugin) {
|
|
17
|
+
this.dependencies.push(plugin);
|
|
18
|
+
}
|
|
19
|
+
async init(browser) {
|
|
20
|
+
if (this.initialized)
|
|
21
|
+
return;
|
|
22
|
+
this.browser = browser;
|
|
23
|
+
const offOnClose = [];
|
|
24
|
+
browser.browserEvents.once('close', async () => {
|
|
25
|
+
offOnClose.forEach(fn => fn());
|
|
26
|
+
this.browser = null;
|
|
27
|
+
this.initialized = false;
|
|
28
|
+
this.startCounter = 0;
|
|
29
|
+
await this.onClose();
|
|
30
|
+
});
|
|
31
|
+
this.startCounter++;
|
|
32
|
+
const thisOnTargetCreated = this.onTargetCreated.bind(this);
|
|
33
|
+
browser.on('targetcreated', thisOnTargetCreated);
|
|
34
|
+
offOnClose.push(() => browser.off('targetcreated', thisOnTargetCreated));
|
|
35
|
+
this.initialized = true;
|
|
36
|
+
this.dependencies.forEach(x => x.init(browser));
|
|
37
|
+
return this.afterLaunch(browser);
|
|
38
|
+
}
|
|
39
|
+
async afterLaunch(_browser) { null; }
|
|
40
|
+
async onClose() { null; }
|
|
41
|
+
async onTargetCreated(target) {
|
|
42
|
+
if (this.isStopped)
|
|
43
|
+
return;
|
|
44
|
+
if (target.type() !== 'page')
|
|
45
|
+
return;
|
|
46
|
+
const page = (0, shared_1.newPage)(await target.page());
|
|
47
|
+
if (page.isClosed())
|
|
48
|
+
return;
|
|
49
|
+
const offOnClose = [];
|
|
50
|
+
page.once('close', async () => {
|
|
51
|
+
offOnClose.forEach(fn => fn());
|
|
52
|
+
});
|
|
53
|
+
const requestHandlers = [];
|
|
54
|
+
page.on('request', request => {
|
|
55
|
+
const _respond = request.respond;
|
|
56
|
+
let responded = 0;
|
|
57
|
+
let respondArgs;
|
|
58
|
+
const _abort = request.abort;
|
|
59
|
+
let aborted = 0;
|
|
60
|
+
let abortArgs;
|
|
61
|
+
const _continue = request.continue;
|
|
62
|
+
let continued = 0;
|
|
63
|
+
let continueArgs;
|
|
64
|
+
const handleRequest = async function () {
|
|
65
|
+
const total = responded + aborted + continued;
|
|
66
|
+
if (!request._interceptionHandled) {
|
|
67
|
+
if (responded === 1)
|
|
68
|
+
await _respond.apply(request, respondArgs);
|
|
69
|
+
else if (responded === 0 && aborted >= 1 && total === requestHandlers.length)
|
|
70
|
+
await _abort.apply(request, abortArgs);
|
|
71
|
+
else if (continued === requestHandlers.length)
|
|
72
|
+
await _continue.apply(request, continueArgs);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
request.respond = async function () { responded++; respondArgs = respondArgs || arguments; await handleRequest(); };
|
|
76
|
+
request.abort = async function () { aborted++; abortArgs = abortArgs || arguments; await handleRequest(); };
|
|
77
|
+
request.continue = async function () { continued++; continueArgs = continueArgs || arguments; await handleRequest(); };
|
|
78
|
+
requestHandlers.forEach(handler => handler(request));
|
|
79
|
+
});
|
|
80
|
+
const _pageOn = page.on;
|
|
81
|
+
page.on = function async(eventName, handler) {
|
|
82
|
+
if (eventName === 'request') {
|
|
83
|
+
requestHandlers.push(handler);
|
|
84
|
+
return page;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return _pageOn.call(page, eventName, handler);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
if (this.requiresInterception) {
|
|
91
|
+
await page.setRequestInterception(true);
|
|
92
|
+
const thisOnRequest = this.onRequest.bind(this);
|
|
93
|
+
page.on('request', thisOnRequest);
|
|
94
|
+
offOnClose.push(() => page.off('request', thisOnRequest));
|
|
95
|
+
}
|
|
96
|
+
const thisOnDialog = this.onDialog.bind(this);
|
|
97
|
+
page.on('dialog', thisOnDialog);
|
|
98
|
+
offOnClose.push(() => page.off('dialog', thisOnDialog));
|
|
99
|
+
await this.onPageCreated(page);
|
|
100
|
+
}
|
|
101
|
+
async onPageCreated(_page) { null; }
|
|
102
|
+
async onRequest(request) {
|
|
103
|
+
const interceptionHandled = request._interceptionHandled;
|
|
104
|
+
if (interceptionHandled)
|
|
105
|
+
return;
|
|
106
|
+
if (this.isStopped)
|
|
107
|
+
return request.continue();
|
|
108
|
+
await this.processRequest(request);
|
|
109
|
+
}
|
|
110
|
+
async processRequest(_request) { null; }
|
|
111
|
+
async onDialog(dialog) {
|
|
112
|
+
if (this.isStopped)
|
|
113
|
+
return;
|
|
114
|
+
const _dismiss = dialog.dismiss;
|
|
115
|
+
dialog.dismiss = async () => {
|
|
116
|
+
if (dialog.handled)
|
|
117
|
+
return;
|
|
118
|
+
await _dismiss.apply(dialog);
|
|
119
|
+
};
|
|
120
|
+
await this.processDialog(dialog);
|
|
121
|
+
}
|
|
122
|
+
async processDialog(_dialog) { null; }
|
|
123
|
+
async beforeRestart() { null; }
|
|
124
|
+
async restart() {
|
|
125
|
+
await this.beforeRestart();
|
|
126
|
+
this.startCounter++;
|
|
127
|
+
if (this.requiresInterception && this.browser)
|
|
128
|
+
this.browser.interceptions++;
|
|
129
|
+
this.dependencies.forEach(x => x.restart());
|
|
130
|
+
await this.afterRestart();
|
|
131
|
+
}
|
|
132
|
+
async afterRestart() { null; }
|
|
133
|
+
async beforeStop() { null; }
|
|
134
|
+
async stop() {
|
|
135
|
+
await this.beforeStop();
|
|
136
|
+
this.startCounter--;
|
|
137
|
+
if (this.requiresInterception && this.browser)
|
|
138
|
+
this.browser.interceptions--;
|
|
139
|
+
if (this.browser && this.browser.interceptions === 0) {
|
|
140
|
+
const pages = await this.browser.pages();
|
|
141
|
+
pages.filter(x => !x.isClosed()).forEach(async (page) => {
|
|
142
|
+
await page.setRequestInterception(false);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
this.dependencies.forEach(x => x.stop());
|
|
146
|
+
await this.afterStop();
|
|
147
|
+
}
|
|
148
|
+
async afterStop() { null; }
|
|
149
|
+
async getFirstPage() {
|
|
150
|
+
if (!this.browser)
|
|
151
|
+
return null;
|
|
152
|
+
const pages = await this.browser.pages();
|
|
153
|
+
const openPages = pages.filter(x => !x.isClosed());
|
|
154
|
+
const activePages = pages.filter(x => x.url() !== 'about:blank');
|
|
155
|
+
return activePages[0] || openPages[0];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.Plugin = Plugin;
|
|
159
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":";AAAA,uCAAuC;;;AAMvC,qCAA2C;AAE3C,MAAa,MAAM;IAAnB;QACY,YAAO,GAAoC,IAAI,CAAC;QAClD,gBAAW,GAAG,KA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E5E,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,aAAa,KAAK,CAAC,EAAE,CAAC;YACrD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YAEzC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,IAAoB,EAAE,EAAE;gBACtE,MAAM,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAEzC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;IACzB,CAAC;IAES,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC;IAE3B,KAAK,CAAC,YAAY;QAC1B,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC;QAE/B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnD,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,aAAa,CAAC,CAAC;QAEjE,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;CACF;AA3LD,wBA2LC","sourcesContent":["/* eslint-disable prefer-rest-params */\n\n// Puppeteer Defaults\nimport * as Puppeteer from 'puppeteer';\n\nimport type { Browser, BrowserContext, Page } from '..';\nimport { Dialog, newPage } from './shared';\n\nexport class Plugin {\n protected browser: Browser | BrowserContext | 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: Browser | BrowserContext) {\n if (this.initialized) return;\n\n this.browser = browser;\n\n const offOnClose: (() => void)[] = [];\n browser.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: Browser | BrowserContext) { 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 = newPage(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: 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 && this.browser) this.browser.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 && this.browser) this.browser.interceptions--;\n\n if (this.browser && this.browser.interceptions === 0) {\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"]}
|
|
@@ -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,
|
|
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,IAAI,CAAC;AAI5B,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,WAAW;cASX,YAAY;IAItB,eAAe,CAAC,OAAO,EAAE,MAAM;IAQ/B,IAAI;IAOJ,IAAI;IAOJ,KAAK;YAMG,YAAY;YAyBZ,kBAAkB;YAOlB,kBAAkB;YAkBlB,mBAAmB;YAqBnB,UAAU;CAYzB"}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// https://gist.github.com/jeroenvisser101/636030fe66ea929b63a33f5cb3a711ad
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ManageCookiesPlugin = void 0;
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const crypto = tslib_1.__importStar(require("crypto"));
|
|
7
|
+
const fs = tslib_1.__importStar(require("fs/promises"));
|
|
8
|
+
const __1 = require("..");
|
|
8
9
|
const sleep = (time) => { return new Promise(resolve => { setTimeout(resolve, time); }); };
|
|
9
10
|
class ManageCookiesPlugin extends __1.Plugin {
|
|
10
11
|
constructor(opts) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/manage.cookies/index.ts"],"names":[],"mappings":";AAAA,2EAA2E
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/manage.cookies/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;;;;AAE3E,uDAAiC;AACjC,wDAAkC;AAGlC,0BAA4B;AAE5B,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,UAAM;IAU7C,YAAY,IAAyB;QACnC,KAAK,EAAE,CAAC;QAVF,i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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\n\nimport * as crypto from 'crypto';\nimport * as fs from 'fs/promises';\nimport type { Cookie } from 'puppeteer';\n\nimport { Plugin } from '..';\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 try {\n await fs.access(this.saveLocation);\n this.allCookies = this.parse((await fs.readFile(this.saveLocation)).toString() || '{}');\n } catch { null; }\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 await fs.writeFile(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 this.browser?.deleteCookie(...await this.getCookies());\n await this.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 this.browser?.deleteCookie(...this.allCookies[this.profile] || []);\n delete this.allCookies[this.profile];\n\n const cookiesString = this.stringify(this.allCookies);\n await fs.writeFile(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 this.browser?.cookies() || [];\n\n return cookies;\n } catch {\n return [];\n }\n }\n}\n"]}
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/manage.localstorage/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAI5B,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,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB;AAED,qBAAa,wBAAyB,SAAQ,MAAM;IAClD,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,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"}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// https://gist.github.com/jeroenvisser101/636030fe66ea929b63a33f5cb3a711ad
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.ManageLocalStoragePlugin = void 0;
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const crypto = tslib_1.__importStar(require("crypto"));
|
|
7
|
+
const fs = tslib_1.__importStar(require("fs/promises"));
|
|
8
|
+
const __1 = require("..");
|
|
8
9
|
const sleep = (time) => { return new Promise(resolve => { setTimeout(resolve, time); }); };
|
|
9
10
|
class ManageLocalStoragePlugin extends __1.Plugin {
|
|
10
11
|
constructor(opts) {
|
|
@@ -1 +1 @@
|
|
|
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,GA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,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
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/manage.localstorage/index.ts"],"names":[],"mappings":";AAAA,2EAA2E;;;;AAE3E,uDAAiC;AACjC,wDAAkC;AAElC,0BAA4B;AAE5B,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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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\n\nimport * as crypto from 'crypto';\nimport * as fs from 'fs/promises';\n\nimport { Plugin } from '..';\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 try {\n await fs.access(this.saveLocation);\n this.allLocalStorage = this.parse((await fs.readFile(this.saveLocation)).toString() || '{}');\n } catch { null; }\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 await fs.writeFile(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 await fs.writeFile(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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/plugins/shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAEvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B,wBAAgB,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,GAAG,IAAI,CAyBrD;AAED,MAAM,WAAW,MAAO,SAAQ,SAAS,CAAC,MAAM;IAC9C,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newPage = newPage;
|
|
4
|
+
function newPage(oldPage) {
|
|
5
|
+
const page = oldPage;
|
|
6
|
+
page.waitAndClick = async (selector, waitOptions, clickOptions) => {
|
|
7
|
+
await page.waitForSelector(selector, waitOptions);
|
|
8
|
+
await page.click(selector, clickOptions);
|
|
9
|
+
};
|
|
10
|
+
page.waitAndType = async (selector, text, waitOptions, typeOptions) => {
|
|
11
|
+
await page.waitForSelector(selector, waitOptions);
|
|
12
|
+
await page.type(selector, text, typeOptions);
|
|
13
|
+
};
|
|
14
|
+
page.withLoader = async (fn, loadingSelector, visibleWaitOptions, hiddenWaitOptions) => {
|
|
15
|
+
const loadingVisible = page.waitForSelector(loadingSelector, visibleWaitOptions);
|
|
16
|
+
const ret = await fn();
|
|
17
|
+
await loadingVisible;
|
|
18
|
+
await page.waitForSelector(loadingSelector, hiddenWaitOptions || { hidden: true });
|
|
19
|
+
return ret;
|
|
20
|
+
};
|
|
21
|
+
return page;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/plugins/shared.ts"],"names":[],"mappings":";;AAKA,0BAyBC;AAzBD,SAAgB,OAAO,CAAC,OAAuB;IAC7C,MAAM,IAAI,GAAG,OAAe,CAAC;IAE7B,IAAI,CAAC,YAAY,GAAG,KAAK,EAAE,QAAgB,EAAE,WAA8C,EAAE,YAA+C,EAAiB,EAAE;QAC7J,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAClD,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAC3C,CAAC,CAAC;IAEF,IAAI,CAAC,WAAW,GAAG,KAAK,EAAE,QAAgB,EAAE,IAAY,EAAE,WAA8C,EAAE,WAAqD,EAAiB,EAAE;QAChL,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAClD,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC,CAAC;IAEF,IAAI,CAAC,UAAU,GAAG,KAAK,EAAI,EAAoB,EAAE,eAAuB,EAAE,kBAAqD,EAAE,iBAAoD,EAAc,EAAE;QACnM,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;QAEjF,MAAM,GAAG,GAAG,MAAM,EAAE,EAAE,CAAC;QAEvB,MAAM,cAAc,CAAC;QACrB,MAAM,IAAI,CAAC,eAAe,CAAC,eAAe,EAAE,iBAAiB,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QAEnF,OAAO,GAAG,CAAC;IACb,CAAC,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["// Puppeteer Defaults\nimport * as Puppeteer from 'puppeteer';\n\nimport type { Page } from '..';\n\nexport function newPage(oldPage: Puppeteer.Page): Page {\n const page = oldPage as Page;\n\n page.waitAndClick = async (selector: string, waitOptions?: Puppeteer.WaitForSelectorOptions, clickOptions?: Readonly<Puppeteer.ClickOptions>): Promise<void> => {\n await page.waitForSelector(selector, waitOptions);\n await page.click(selector, clickOptions);\n };\n\n page.waitAndType = async (selector: string, text: string, waitOptions?: Puppeteer.WaitForSelectorOptions, typeOptions?: Readonly<Puppeteer.KeyboardTypeOptions>): Promise<void> => {\n await page.waitForSelector(selector, waitOptions);\n await page.type(selector, text, typeOptions);\n };\n\n page.withLoader = async<T>(fn: () => Promise<T>, loadingSelector: string, visibleWaitOptions?: Puppeteer.WaitForSelectorOptions, hiddenWaitOptions?: Puppeteer.WaitForSelectorOptions): Promise<T> => {\n const loadingVisible = page.waitForSelector(loadingSelector, visibleWaitOptions);\n\n const ret = await fn();\n\n await loadingVisible;\n await page.waitForSelector(loadingSelector, hiddenWaitOptions || { hidden: true });\n\n return ret;\n };\n\n return page;\n}\n\nexport interface Dialog extends Puppeteer.Dialog {\n handled: boolean;\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Puppeteer from 'puppeteer';
|
|
2
|
-
import { Page
|
|
2
|
+
import type { Page } from '../..';
|
|
3
|
+
import { Plugin } from '..';
|
|
3
4
|
import { AvoidDetectionPlugin } from './../avoid.detection';
|
|
4
5
|
export declare class SolveRecaptchasPlugin extends Plugin {
|
|
5
6
|
dependencies: AvoidDetectionPlugin[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/solve.recaptchas/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAGvC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/solve.recaptchas/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAC;AAGvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAM5D,qBAAa,qBAAsB,SAAQ,MAAM;IAC/C,YAAY,yBAAgC;IAC5C,gBAAgB,CAAC,EAAE,MAAM,CAAC;gBAEd,gBAAgB,EAAE,MAAM;IAK9B,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM;IAK3C,UAAU,CAAC,IAAI,EAAE,IAAI;IAKrB,cAAc,CAAC,IAAI,EAAE,IAAI;CA8EhC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SolveRecaptchasPlugin = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
5
6
|
const ghost_cursor_1 = require("ghost-cursor");
|
|
6
|
-
const __1 = require("
|
|
7
|
+
const __1 = require("..");
|
|
7
8
|
const avoid_detection_1 = require("./../avoid.detection");
|
|
8
9
|
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
9
10
|
const injection = require(path.resolve(`${__dirname}/injections`) + '/utils.js');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/solve.recaptchas/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/solve.recaptch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C,qBAAqB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;YACjF,CAAC;YAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAEnC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;YAE7F,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;AAjGD,sDAiGC;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 * as path from 'path';\nimport * as Puppeteer from 'puppeteer';\nimport { GhostCursor } from 'ghost-cursor';\n\nimport type { Page } from '../..';\nimport { Plugin } from '..';\nimport { AvoidDetectionPlugin } from './../avoid.detection';\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 SolveRecaptchasPlugin 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: 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: 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: 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 = new GhostCursor(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 const isFinished = async () => {\n if (!(await this.hasCaptcha(page))) return true;\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 fetch('https://api.wit.ai/speech?v=20220527', {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${this.witAiAccessToken}`,\n 'Content-Type': 'audio/wav',\n },\n body: audioBuffer,\n });\n\n if (!response.ok) {\n throw new Error(`Wit.ai API error: ${response.status} ${response.statusText}`);\n }\n\n const text = await response.text();\n\n const data = JSON.parse(text.split('\\r\\n').filter(line => line.trim()).slice(-1)[0] || '{}');\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}\n"]}
|