improve
Browse files
main.go
CHANGED
|
@@ -16,7 +16,6 @@ import (
|
|
| 16 |
|
| 17 |
"github.com/chromedp/cdproto/emulation"
|
| 18 |
"github.com/chromedp/cdproto/network"
|
| 19 |
-
"github.com/chromedp/cdproto/page"
|
| 20 |
"github.com/chromedp/cdproto/security"
|
| 21 |
"github.com/chromedp/cdproto/target"
|
| 22 |
"github.com/chromedp/chromedp"
|
|
@@ -117,6 +116,16 @@ func initGlobalBrowser() {
|
|
| 117 |
chromedp.Flag("disable-blink-features", "AutomationControlled"),
|
| 118 |
chromedp.Flag("exclude-switches", "enable-automation"),
|
| 119 |
chromedp.Flag("use-fake-codec-for-media-stream", true),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
chromedp.Flag("disable-infobars", true),
|
| 121 |
chromedp.Flag("disable-notifications", true),
|
| 122 |
chromedp.Flag("disable-popup-blocking", true),
|
|
@@ -125,6 +134,9 @@ func initGlobalBrowser() {
|
|
| 125 |
chromedp.Flag("no-first-run", true),
|
| 126 |
chromedp.Flag("no-default-browser-check", true),
|
| 127 |
chromedp.Flag("window-size", "1366,768"),
|
|
|
|
|
|
|
|
|
|
| 128 |
chromedp.Flag("blink-settings", "primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4"),
|
| 129 |
)
|
| 130 |
|
|
@@ -183,8 +195,7 @@ func executeHandler(w http.ResponseWriter, r *http.Request) {
|
|
| 183 |
networkRegistry := make(map[network.RequestID]*SniffedNetworkActivity)
|
| 184 |
var closedRequestIDs []network.RequestID
|
| 185 |
|
| 186 |
-
|
| 187 |
-
if forceSniff {
|
| 188 |
_ = chromedp.Run(timeoutCtx, network.Enable())
|
| 189 |
|
| 190 |
chromedp.ListenTarget(timeoutCtx, func(ev interface{}) {
|
|
@@ -229,56 +240,7 @@ func executeHandler(w http.ResponseWriter, r *http.Request) {
|
|
| 229 |
_ = chromedp.Run(timeoutCtx, chromedp.ActionFunc(func(ctx context.Context) error {
|
| 230 |
_ = target.SetAutoAttach(true, false).WithFlatten(true).Do(ctx)
|
| 231 |
|
| 232 |
-
|
| 233 |
-
Object.defineProperty(navigator, 'webdriver', { get: () => false, configurable: true });
|
| 234 |
-
Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'], configurable: true });
|
| 235 |
-
Object.defineProperty(navigator, 'platform', { get: () => 'Win32', configurable: true });
|
| 236 |
-
Object.defineProperty(navigator, 'hardwareConcurrency', { get: () => 8, configurable: true });
|
| 237 |
-
Object.defineProperty(navigator, 'deviceMemory', { get: () => 8, configurable: true });
|
| 238 |
-
Object.defineProperty(navigator, 'maxTouchPoints', { get: () => 0, configurable: true });
|
| 239 |
-
window.chrome = { runtime: {} };
|
| 240 |
-
|
| 241 |
-
const origToDataURL = HTMLCanvasElement.prototype.toDataURL;
|
| 242 |
-
HTMLCanvasElement.prototype.toDataURL = function(type) {
|
| 243 |
-
const ctx = this.getContext('2d');
|
| 244 |
-
if (ctx) {
|
| 245 |
-
try {
|
| 246 |
-
const pixel = ctx.getImageData(0, 0, 1, 1).data;
|
| 247 |
-
if (pixel[3] !== 0) {
|
| 248 |
-
ctx.fillStyle = 'rgba(255,255,255,0.001)';
|
| 249 |
-
ctx.fillRect(0, 0, 1, 1);
|
| 250 |
-
}
|
| 251 |
-
} catch (e) {}
|
| 252 |
-
}
|
| 253 |
-
return origToDataURL.apply(this, arguments);
|
| 254 |
-
};
|
| 255 |
-
|
| 256 |
-
const patchWebGL = (proto) => {
|
| 257 |
-
const orig = proto.getParameter;
|
| 258 |
-
proto.getParameter = function(param) {
|
| 259 |
-
if (param === 37445) return 'Google Inc. (Intel)';
|
| 260 |
-
if (param === 37446) return 'ANGLE (Intel, Intel(R) UHD Graphics 620 Direct3D11 vs_5_0 ps_5_0, D3D11)';
|
| 261 |
-
return orig.call(this, param);
|
| 262 |
-
};
|
| 263 |
-
};
|
| 264 |
-
if (typeof WebGLRenderingContext !== 'undefined') patchWebGL(WebGLRenderingContext.prototype);
|
| 265 |
-
if (typeof WebGL2RenderingContext !== 'undefined') patchWebGL(WebGL2RenderingContext.prototype);
|
| 266 |
-
|
| 267 |
-
const origCreateAnalyser = AudioContext.prototype?.createAnalyser;
|
| 268 |
-
if (origCreateAnalyser) {
|
| 269 |
-
AudioContext.prototype.createAnalyser = function() {
|
| 270 |
-
const analyser = origCreateAnalyser.call(this);
|
| 271 |
-
const origGetFloatFreq = analyser.getFloatFrequencyData.bind(analyser);
|
| 272 |
-
analyser.getFloatFrequencyData = function(array) {
|
| 273 |
-
origGetFloatFreq(array);
|
| 274 |
-
for (let i = 0; i < array.length; i++) {
|
| 275 |
-
array[i] += (Math.random() - 0.5) * 0.0001;
|
| 276 |
-
}
|
| 277 |
-
};
|
| 278 |
-
return analyser;
|
| 279 |
-
};
|
| 280 |
-
}
|
| 281 |
-
|
| 282 |
window.__turnstileToken = '';
|
| 283 |
const hookTurnstile = () => {
|
| 284 |
if (!window.turnstile || window.turnstile.__hooked) return;
|
|
@@ -301,8 +263,8 @@ func executeHandler(w http.ResponseWriter, r *http.Request) {
|
|
| 301 |
get() { return this.__ts; }
|
| 302 |
});
|
| 303 |
`
|
| 304 |
-
|
| 305 |
-
return
|
| 306 |
}))
|
| 307 |
|
| 308 |
if req.Width > 0 && req.Height > 0 {
|
|
@@ -450,7 +412,7 @@ func executeHandler(w http.ResponseWriter, r *http.Request) {
|
|
| 450 |
var token interface{}
|
| 451 |
harvestScript := `
|
| 452 |
(async () => {
|
| 453 |
-
for (let i = 0; i <
|
| 454 |
if (window.__turnstileToken && window.__turnstileToken.length > 10) {
|
| 455 |
return window.__turnstileToken;
|
| 456 |
}
|
|
@@ -460,7 +422,7 @@ func executeHandler(w http.ResponseWriter, r *http.Request) {
|
|
| 460 |
if (input && input.value && input.value.length > 10) {
|
| 461 |
return input.value;
|
| 462 |
}
|
| 463 |
-
await new Promise(r => setTimeout(r,
|
| 464 |
}
|
| 465 |
return "";
|
| 466 |
})();
|
|
|
|
| 16 |
|
| 17 |
"github.com/chromedp/cdproto/emulation"
|
| 18 |
"github.com/chromedp/cdproto/network"
|
|
|
|
| 19 |
"github.com/chromedp/cdproto/security"
|
| 20 |
"github.com/chromedp/cdproto/target"
|
| 21 |
"github.com/chromedp/chromedp"
|
|
|
|
| 116 |
chromedp.Flag("disable-blink-features", "AutomationControlled"),
|
| 117 |
chromedp.Flag("exclude-switches", "enable-automation"),
|
| 118 |
chromedp.Flag("use-fake-codec-for-media-stream", true),
|
| 119 |
+
|
| 120 |
+
chromedp.Flag("disable-gl-drawing-for-tests", true),
|
| 121 |
+
chromedp.Flag("disable-software-rasterizer", true),
|
| 122 |
+
chromedp.Flag("disable-canvas-aa", true),
|
| 123 |
+
chromedp.Flag("disable-2d-canvas-clip-antialiasing", true),
|
| 124 |
+
chromedp.Flag("disable-2d-canvas-image-chromium", true),
|
| 125 |
+
chromedp.Flag("disable-gpu-rasterization", true),
|
| 126 |
+
chromedp.Flag("no-zygote", true),
|
| 127 |
+
chromedp.Flag("single-process", true),
|
| 128 |
+
|
| 129 |
chromedp.Flag("disable-infobars", true),
|
| 130 |
chromedp.Flag("disable-notifications", true),
|
| 131 |
chromedp.Flag("disable-popup-blocking", true),
|
|
|
|
| 134 |
chromedp.Flag("no-first-run", true),
|
| 135 |
chromedp.Flag("no-default-browser-check", true),
|
| 136 |
chromedp.Flag("window-size", "1366,768"),
|
| 137 |
+
|
| 138 |
+
chromedp.Flag("lang", "en-US,en"),
|
| 139 |
+
chromedp.Flag("platform", "Win32"),
|
| 140 |
chromedp.Flag("blink-settings", "primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4"),
|
| 141 |
)
|
| 142 |
|
|
|
|
| 195 |
networkRegistry := make(map[network.RequestID]*SniffedNetworkActivity)
|
| 196 |
var closedRequestIDs []network.RequestID
|
| 197 |
|
| 198 |
+
if req.SniffNetwork {
|
|
|
|
| 199 |
_ = chromedp.Run(timeoutCtx, network.Enable())
|
| 200 |
|
| 201 |
chromedp.ListenTarget(timeoutCtx, func(ev interface{}) {
|
|
|
|
| 240 |
_ = chromedp.Run(timeoutCtx, chromedp.ActionFunc(func(ctx context.Context) error {
|
| 241 |
_ = target.SetAutoAttach(true, false).WithFlatten(true).Do(ctx)
|
| 242 |
|
| 243 |
+
hookScript := `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
window.__turnstileToken = '';
|
| 245 |
const hookTurnstile = () => {
|
| 246 |
if (!window.turnstile || window.turnstile.__hooked) return;
|
|
|
|
| 263 |
get() { return this.__ts; }
|
| 264 |
});
|
| 265 |
`
|
| 266 |
+
var tmp interface{}
|
| 267 |
+
return chromedp.Evaluate(hookScript, &tmp).Do(ctx)
|
| 268 |
}))
|
| 269 |
|
| 270 |
if req.Width > 0 && req.Height > 0 {
|
|
|
|
| 412 |
var token interface{}
|
| 413 |
harvestScript := `
|
| 414 |
(async () => {
|
| 415 |
+
for (let i = 0; i < 40; i++) {
|
| 416 |
if (window.__turnstileToken && window.__turnstileToken.length > 10) {
|
| 417 |
return window.__turnstileToken;
|
| 418 |
}
|
|
|
|
| 422 |
if (input && input.value && input.value.length > 10) {
|
| 423 |
return input.value;
|
| 424 |
}
|
| 425 |
+
await new Promise(r => setTimeout(r, 700));
|
| 426 |
}
|
| 427 |
return "";
|
| 428 |
})();
|