-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathchrome_stealth.js
More file actions
82 lines (81 loc) · 2.55 KB
/
chrome_stealth.js
File metadata and controls
82 lines (81 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Chrome Stealth Patch - Additional evasion for Cloudflare and other bot detection
// Based on https://github.com/jonfriesen/playwright-go-stealth/issues/2
(() => {
const windowsPatch = (w) => {
w.chrome = {
app: {
isInstalled: false,
InstallState: {
DISABLED: "disabled",
INSTALLED: "installed",
NOT_INSTALLED: "not_installed",
},
RunningState: {
CANNOT_RUN: "cannot_run",
READY_TO_RUN: "ready_to_run",
RUNNING: "running",
},
},
loadTimes: () => {},
csi: () => {},
};
w.console.debug = () => {};
w.console.log = () => {};
w.console.context = () => {};
w.navigator.permissions.query = new Proxy(navigator.permissions.query, {
apply: async function (target, thisArg, args) {
try {
const result = await Reflect.apply(target, thisArg, args);
if (result?.state === "prompt") {
Object.defineProperty(result, "state", { value: "denied" });
}
return Promise.resolve(result);
} catch (error) {
return Promise.reject(error);
}
},
});
Element.prototype._addEventListener = Element.prototype.addEventListener;
Element.prototype.addEventListener = function () {
let args = [...arguments];
let temp = args[1];
args[1] = function () {
let args2 = [...arguments];
args2[0] = Object.assign({}, args2[0]);
args2[0].isTrusted = true;
return temp(...args2);
};
return this._addEventListener(...args);
};
};
const cloudflareClicker = (w) => {
if (w?.document && w.location.host === "challenges.cloudflare.com") {
const targetSelector = "input[type=checkbox]";
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === "childList") {
const addedNodes = Array.from(mutation.addedNodes);
for (const addedNode of addedNodes) {
if (addedNode.nodeType === addedNode.ELEMENT_NODE) {
const node = addedNode?.querySelector(targetSelector);
if (node) {
node.parentElement.click();
}
}
}
}
}
});
const observerOptions = {
childList: true,
subtree: true,
};
observer.observe(
w.document.documentElement || w.document,
observerOptions
);
}
};
windowsPatch(window);
cloudflareClicker(window);
})();