cloakbrowser 0.3.21 → 0.3.23
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/dist/config.d.ts +1 -1
- package/dist/config.js +2 -2
- package/dist/human/index.d.ts.map +1 -1
- package/dist/human/index.js +11 -2
- package/dist/human/index.js.map +1 -1
- package/dist/human-puppeteer/index.d.ts +63 -0
- package/dist/human-puppeteer/index.d.ts.map +1 -0
- package/dist/human-puppeteer/index.js +780 -0
- package/dist/human-puppeteer/index.js.map +1 -0
- package/dist/human-puppeteer/keyboard.d.ts +16 -0
- package/dist/human-puppeteer/keyboard.d.ts.map +1 -0
- package/dist/human-puppeteer/keyboard.js +157 -0
- package/dist/human-puppeteer/keyboard.js.map +1 -0
- package/dist/human-puppeteer/scroll.d.ts +26 -0
- package/dist/human-puppeteer/scroll.d.ts.map +1 -0
- package/dist/human-puppeteer/scroll.js +130 -0
- package/dist/human-puppeteer/scroll.js.map +1 -0
- package/dist/puppeteer.d.ts +7 -5
- package/dist/puppeteer.d.ts.map +1 -1
- package/dist/puppeteer.js +16 -8
- package/dist/puppeteer.js.map +1 -1
- package/package.json +5 -1
- package/dist/stealth-eval.d.ts +0 -40
- package/dist/stealth-eval.d.ts.map +0 -1
- package/dist/stealth-eval.js +0 -145
- package/dist/stealth-eval.js.map +0 -1
package/dist/stealth-eval.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stealth evaluate — run JS in a CDP isolated world.
|
|
3
|
-
*
|
|
4
|
-
* Provides page.stealthEvaluate(expression) on every page returned by
|
|
5
|
-
* cloakbrowser launch functions. Produces clean Error.stack traces (no
|
|
6
|
-
* `eval at evaluate :302:` leak) and full variable isolation from main
|
|
7
|
-
* world JS. Context auto-recreates after navigation.
|
|
8
|
-
*
|
|
9
|
-
* The same StealthEval instances are reused by the humanize layer
|
|
10
|
-
* (human/index.ts) for stealth DOM queries.
|
|
11
|
-
*/
|
|
12
|
-
// ============================================================================
|
|
13
|
-
// Isolated world class
|
|
14
|
-
// ============================================================================
|
|
15
|
-
/**
|
|
16
|
-
* Manages a CDP isolated execution context for DOM reads.
|
|
17
|
-
* Produces clean Error.stack traces (no 'eval at evaluate :302:')
|
|
18
|
-
* and is invisible to querySelector monkey-patches in the main world.
|
|
19
|
-
*
|
|
20
|
-
* Context ID is invalidated on navigation and auto-recreated on next call.
|
|
21
|
-
*/
|
|
22
|
-
export class StealthEval {
|
|
23
|
-
cdp = null;
|
|
24
|
-
contextId = null;
|
|
25
|
-
page;
|
|
26
|
-
constructor(page) {
|
|
27
|
-
this.page = page;
|
|
28
|
-
}
|
|
29
|
-
async ensureCdp() {
|
|
30
|
-
if (!this.cdp) {
|
|
31
|
-
this.cdp = await this.page.context().newCDPSession(this.page);
|
|
32
|
-
}
|
|
33
|
-
return this.cdp;
|
|
34
|
-
}
|
|
35
|
-
async createWorld() {
|
|
36
|
-
const cdp = await this.ensureCdp();
|
|
37
|
-
const tree = await cdp.send('Page.getFrameTree');
|
|
38
|
-
const frameId = tree.frameTree.frame.id;
|
|
39
|
-
const result = await cdp.send('Page.createIsolatedWorld', {
|
|
40
|
-
frameId,
|
|
41
|
-
worldName: '',
|
|
42
|
-
grantUniveralAccess: true,
|
|
43
|
-
});
|
|
44
|
-
const ctxId = result.executionContextId;
|
|
45
|
-
this.contextId = ctxId;
|
|
46
|
-
return ctxId;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Evaluate a JS expression in the isolated world.
|
|
50
|
-
* Auto-recreates the world if the context was invalidated (navigation).
|
|
51
|
-
* Returns the result value, or undefined on failure.
|
|
52
|
-
*/
|
|
53
|
-
async evaluate(expression) {
|
|
54
|
-
if (this.contextId === null) {
|
|
55
|
-
try {
|
|
56
|
-
await this.createWorld();
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
63
|
-
try {
|
|
64
|
-
const cdp = await this.ensureCdp();
|
|
65
|
-
const result = await cdp.send('Runtime.evaluate', {
|
|
66
|
-
expression,
|
|
67
|
-
contextId: this.contextId,
|
|
68
|
-
returnByValue: true,
|
|
69
|
-
});
|
|
70
|
-
if (result.exceptionDetails) {
|
|
71
|
-
if (attempt === 0) {
|
|
72
|
-
await this.createWorld();
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
return result.result?.value;
|
|
78
|
-
}
|
|
79
|
-
catch {
|
|
80
|
-
if (attempt === 0) {
|
|
81
|
-
this.contextId = null;
|
|
82
|
-
try {
|
|
83
|
-
await this.createWorld();
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
return undefined;
|
|
87
|
-
}
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
/** Mark context as stale — call after navigation. */
|
|
96
|
-
invalidate() {
|
|
97
|
-
this.contextId = null;
|
|
98
|
-
}
|
|
99
|
-
/** Get the underlying CDP session (reused for Input.dispatchKeyEvent etc.). */
|
|
100
|
-
async getCdpSession() {
|
|
101
|
-
return this.ensureCdp();
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
// ============================================================================
|
|
105
|
-
// Page / context / browser patching
|
|
106
|
-
// ============================================================================
|
|
107
|
-
function patchPage(page) {
|
|
108
|
-
if (page.stealthEvaluate)
|
|
109
|
-
return;
|
|
110
|
-
const existing = page._stealthWorld;
|
|
111
|
-
const stealth = existing instanceof StealthEval ? existing : new StealthEval(page);
|
|
112
|
-
page._stealthWorld = stealth;
|
|
113
|
-
page.stealthEvaluate = stealth.evaluate.bind(stealth);
|
|
114
|
-
}
|
|
115
|
-
export function patchContext(context) {
|
|
116
|
-
if (context._stealthEvalPatched)
|
|
117
|
-
return;
|
|
118
|
-
context._stealthEvalPatched = true;
|
|
119
|
-
for (const p of context.pages()) {
|
|
120
|
-
patchPage(p);
|
|
121
|
-
}
|
|
122
|
-
const origNewPage = context.newPage.bind(context);
|
|
123
|
-
context.newPage = async (...args) => {
|
|
124
|
-
const page = await origNewPage(...args);
|
|
125
|
-
patchPage(page);
|
|
126
|
-
return page;
|
|
127
|
-
};
|
|
128
|
-
context.on('page', (page) => patchPage(page));
|
|
129
|
-
}
|
|
130
|
-
export function patchBrowser(browser) {
|
|
131
|
-
const origNewContext = browser.newContext.bind(browser);
|
|
132
|
-
browser.newContext = async (...args) => {
|
|
133
|
-
const ctx = await origNewContext(...args);
|
|
134
|
-
patchContext(ctx);
|
|
135
|
-
return ctx;
|
|
136
|
-
};
|
|
137
|
-
const origNewPage = browser.newPage.bind(browser);
|
|
138
|
-
browser.newPage = async (...args) => {
|
|
139
|
-
const page = await origNewPage(...args);
|
|
140
|
-
patchContext(page.context());
|
|
141
|
-
patchPage(page);
|
|
142
|
-
return page;
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
//# sourceMappingURL=stealth-eval.js.map
|
package/dist/stealth-eval.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stealth-eval.js","sourceRoot":"","sources":["../src/stealth-eval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;;;;;GAMG;AACH,MAAM,OAAO,WAAW;IACd,GAAG,GAAsB,IAAI,CAAC;IAC9B,SAAS,GAAkB,IAAI,CAAC;IAChC,IAAI,CAAO;IAEnB,YAAY,IAAU;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEO,KAAK,CAAC,SAAS;QACrB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACd,IAAI,CAAC,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,E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