and commited on
Commit
61c2768
·
1 Parent(s): dd154fc
Files changed (2) hide show
  1. Dockerfile +3 -1
  2. index.mjs +422 -1
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM mcr.microsoft.com/playwright:v1.40.0-jammy
2
 
3
  WORKDIR /code
4
 
@@ -7,6 +7,8 @@ WORKDIR /code
7
  RUN npm i [email protected]
8
  RUN npm i web-locks
9
  RUN npm i ws
 
 
10
 
11
  COPY . .
12
 
 
1
+ FROM mcr.microsoft.com/playwright:v1.41.2-jammy
2
 
3
  WORKDIR /code
4
 
 
7
  RUN npm i [email protected]
8
  RUN npm i web-locks
9
  RUN npm i ws
10
+ RUN npm i user-agents
11
+ RUN npm i uuid
12
 
13
  COPY . .
14
 
index.mjs CHANGED
@@ -8,10 +8,14 @@ import fs from 'fs';
8
  import { setTimeout } from 'timers/promises';
9
  import { WebSocketServer } from 'ws';
10
 
 
 
11
 
12
  // npm i playwright
13
  // npm i web-locks
14
  // npm i ws
 
 
15
 
16
  // nohup cloudflared tunnel --url http://localhost:8080 --no-autoupdate & (or setsid)
17
  // setsid node playwright.mjs (nohup doesnt work)
@@ -140,10 +144,420 @@ async function evaluate(url, code) {
140
  return result;
141
  }
142
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  const server = http.createServer(async function(req, res) {
144
  const {query, pathname} = url.parse(req.url, true);
145
 
146
- console.log(req.url);
147
 
148
  res.setHeader('Access-Control-Allow-Origin', '*')
149
 
@@ -166,6 +580,13 @@ const server = http.createServer(async function(req, res) {
166
  // res.writeHead(200,{'Content-type':'image/png'});
167
  // readStream.pipe(res);
168
  // res.end();
 
 
 
 
 
 
 
169
  } else if (pathname == '/evaluate') {
170
  const buffers = [];
171
  for await (const chunk of req) {
 
8
  import { setTimeout } from 'timers/promises';
9
  import { WebSocketServer } from 'ws';
10
 
11
+ import UserAgent from 'user-agents';
12
+ import { v4 as uuidv4 } from 'uuid';
13
 
14
  // npm i playwright
15
  // npm i web-locks
16
  // npm i ws
17
+ // npm i user-agents
18
+ // npm i uuid
19
 
20
  // nohup cloudflared tunnel --url http://localhost:8080 --no-autoupdate & (or setsid)
21
  // setsid node playwright.mjs (nohup doesnt work)
 
144
  return result;
145
  }
146
 
147
+
148
+
149
+
150
+ async function test_bot(url) {
151
+ // https://gist.github.com/nicoandmee/1ec1b6a07c94f82df41d2496194ef3a6
152
+
153
+ const UINT32_MAX = (2 ** 32) - 1;
154
+ const WEBGL_RENDERERS = ['ANGLE (NVIDIA Quadro 2000M Direct3D11 vs_5_0 ps_5_0)', 'ANGLE (NVIDIA Quadro K420 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA Quadro 2000M Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA Quadro K2000M Direct3D11 vs_5_0 ps_5_0)', 'ANGLE (Intel(R) HD Graphics Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics Family Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (ATI Radeon HD 3800 Series Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics 4000 Direct3D11 vs_5_0 ps_5_0)', 'ANGLE (Intel(R) HD Graphics 4000 Direct3D11 vs_5_0 ps_5_0)', 'ANGLE (AMD Radeon R9 200 Series Direct3D11 vs_5_0 ps_5_0)', 'ANGLE (Intel(R) HD Graphics Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics Family Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics Family Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics 4000 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics 3000 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Mobile Intel(R) 4 Series Express Chipset Family Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) G33/G31 Express Chipset Family Direct3D9Ex vs_0_0 ps_2_0)', 'ANGLE (Intel(R) Graphics Media Accelerator 3150 Direct3D9Ex vs_0_0 ps_2_0)', 'ANGLE (Intel(R) G41 Express Chipset Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce 6150SE nForce 430 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics 4000)', 'ANGLE (Mobile Intel(R) 965 Express Chipset Family Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics Family)', 'ANGLE (NVIDIA GeForce GTX 760 Direct3D11 vs_5_0 ps_5_0)', 'ANGLE (NVIDIA GeForce GTX 760 Direct3D11 vs_5_0 ps_5_0)', 'ANGLE (NVIDIA GeForce GTX 760 Direct3D11 vs_5_0 ps_5_0)', 'ANGLE (AMD Radeon HD 6310 Graphics Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) Graphics Media Accelerator 3600 Series Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) G33/G31 Express Chipset Family Direct3D9 vs_0_0 ps_2_0)', 'ANGLE (AMD Radeon HD 6320 Graphics Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) G33/G31 Express Chipset Family (Microsoft Corporation - WDDM 1.0) Direct3D9Ex vs_0_0 ps_2_0)', 'ANGLE (Intel(R) G41 Express Chipset)', 'ANGLE (ATI Mobility Radeon HD 5470 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) Q45/Q43 Express Chipset Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce 310M Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) G41 Express Chipset Direct3D9 vs_3_0 ps_3_0)', 'ANGLE (Mobile Intel(R) 45 Express Chipset Family (Microsoft Corporation - WDDM 1.1) Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce GT 440 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (ATI Radeon HD 4300/4500 Series Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon HD 7310 Graphics Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics)', 'ANGLE (Intel(R) 4 Series Internal Chipset Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon(TM) HD 6480G Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (ATI Radeon HD 3200 Graphics Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon HD 7800 Series Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) G41 Express Chipset (Microsoft Corporation - WDDM 1.1) Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce 210 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce GT 630 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon HD 7340 Graphics Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) 82945G Express Chipset Family Direct3D9 vs_0_0 ps_2_0)', 'ANGLE (NVIDIA GeForce GT 430 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce 7025 / NVIDIA nForce 630a Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) Q35 Express Chipset Family Direct3D9Ex vs_0_0 ps_2_0)', 'ANGLE (Intel(R) HD Graphics 4600 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon HD 7520G Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD 760G (Microsoft Corporation WDDM 1.1) Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce GT 220 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce 9500 GT Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics Family Direct3D9 vs_3_0 ps_3_0)', 'ANGLE (Intel(R) Graphics Media Accelerator HD Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce 9800 GT Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) Q965/Q963 Express Chipset Family (Microsoft Corporation - WDDM 1.0) Direct3D9Ex vs_0_0 ps_2_0)', 'ANGLE (NVIDIA GeForce GTX 550 Ti Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) Q965/Q963 Express Chipset Family Direct3D9Ex vs_0_0 ps_2_0)', 'ANGLE (AMD M880G with ATI Mobility Radeon HD 4250 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce GTX 650 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (ATI Mobility Radeon HD 5650 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (ATI Radeon HD 4200 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon HD 7700 Series Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) G33/G31 Express Chipset Family)', 'ANGLE (Intel(R) 82945G Express Chipset Family Direct3D9Ex vs_0_0 ps_2_0)', 'ANGLE (SiS Mirage 3 Graphics Direct3D9Ex vs_2_0 ps_2_0)', 'ANGLE (NVIDIA GeForce GT 430)', 'ANGLE (AMD RADEON HD 6450 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (ATI Radeon 3000 Graphics Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) 4 Series Internal Chipset Direct3D9 vs_3_0 ps_3_0)', 'ANGLE (Intel(R) Q35 Express Chipset Family (Microsoft Corporation - WDDM 1.0) Direct3D9Ex vs_0_0 ps_2_0)', 'ANGLE (NVIDIA GeForce GT 220 Direct3D9 vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon HD 7640G Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD 760G Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon HD 6450 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce GT 640 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce 9200 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce GT 610 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon HD 6290 Graphics Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (ATI Mobility Radeon HD 4250 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce 8600 GT Direct3D9 vs_3_0 ps_3_0)', 'ANGLE (ATI Radeon HD 5570 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon HD 6800 Series Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) G45/G43 Express Chipset Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (ATI Radeon HD 4600 Series Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA Quadro NVS 160M Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics 3000)', 'ANGLE (NVIDIA GeForce G100)', 'ANGLE (AMD Radeon HD 8610G + 8500M Dual Graphics Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Mobile Intel(R) 4 Series Express Chipset Family Direct3D9 vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce 7025 / NVIDIA nForce 630a (Microsoft Corporation - WDDM) Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) Q965/Q963 Express Chipset Family Direct3D9 vs_0_0 ps_2_0)', 'ANGLE (AMD RADEON HD 6350 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (ATI Radeon HD 5450 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce 9500 GT)', 'ANGLE (AMD Radeon HD 6500M/5600/5700 Series Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Mobile Intel(R) 965 Express Chipset Family)', 'ANGLE (NVIDIA GeForce 8400 GS Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (Intel(R) HD Graphics Direct3D9 vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce GTX 560 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce GT 620 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce GTX 660 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon(TM) HD 6520G Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA GeForce GT 240 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (AMD Radeon HD 8240 Direct3D9Ex vs_3_0 ps_3_0)', 'ANGLE (NVIDIA Quadro NVS 140M)', 'ANGLE (Intel(R) Q35 Express Chipset Family Direct3D9 vs_0_0 ps_2_0)'];
155
+
156
+ function getBrowserfingerprint(buid, emulateFlag = 'desktop') {
157
+ const generateUserAgent = new UserAgent({
158
+ deviceCategory: emulateFlag,
159
+ });
160
+ const fingerprints = Array(1000).fill().map(() => generateUserAgent());
161
+
162
+ const WEBGL_PARAMETER = {
163
+ WEBGL_VENDOR: 'Google Inc.',
164
+ WEBGL_RENDERER: WEBGL_RENDERERS[Math.floor(Math.random() * WEBGL_RENDERERS.length)],
165
+ };
166
+
167
+ const fingerprint = Object.assign(fingerprints[Math.floor(Math.random() * fingerprints.length)].data, WEBGL_PARAMETER);
168
+
169
+ const buidHash = crypto.createHash('sha512').update(buid).digest();
170
+ fingerprint.BUID = buidHash.toString('base64');
171
+
172
+ fingerprint.random = (index) => {
173
+ const idx = index % 124;
174
+ if (idx < 62) return buidHash.readUInt32BE(idx) / UINT32_MAX;
175
+ return buidHash.readUInt32LE(idx - 62) / UINT32_MAX;
176
+ };
177
+ return fingerprint;
178
+ }
179
+
180
+ async function cloak(page, fingerprint, {
181
+ minWidth = 1280,
182
+ minHeight = 1024,
183
+ } = {}) {
184
+ console.debug(`fingerprint-webgl-vendor-${fingerprint.WEBGL_VENDOR}`);
185
+ console.debug(`fingerprint-webgl-renderer-${fingerprint.WEBGL_RENDERER}`);
186
+ console.debug(`fingerprint-ua-ua-${fingerprint.userAgent}`);
187
+ console.debug(`fingerprint-ua-platform-${fingerprint.platform}`);
188
+ console.debug(`fingerprint-deviceCategory-${fingerprint.deviceCategory}`);
189
+ console.debug(`fingerprint-viewportHeight-${fingerprint.viewportHeight}`);
190
+ console.debug(`fingerprint-viewportWidth-${fingerprint.viewportWidth}`);
191
+
192
+
193
+ const LOG_OVERRIDE = true;
194
+
195
+ if (LOG_OVERRIDE) {
196
+ await page.on('console', (msg) => {
197
+ if (msg && msg.text) {
198
+ if (typeof msg.text === 'function') {
199
+ debugConsole('PAGE LOG:', msg.text());
200
+ } else {
201
+ debugConsole('PAGE LOG:', msg.text);
202
+ }
203
+ } else {
204
+ debugConsole('PAGE LOG:', msg);
205
+ }
206
+ });
207
+ await page.on('pageerror', (err) => debug('PAGE ERR:', err));
208
+ }
209
+
210
+ const DIMENSION = {
211
+ isLandscape: true,
212
+ width: minWidth > fingerprint.viewportWidth ? minWidth : (parseInt(minWidth + (fingerprint.random(0)
213
+ * (fingerprint.screenWidth - minWidth)), 10)),
214
+ height: minHeight > fingerprint.viewportHeight ? minHeight : (parseInt(minHeight + (fingerprint.random(1)
215
+ * (fingerprint.screenHeight - minHeight)), 10)),
216
+ };
217
+
218
+ await page.addInitScript(async (fingerprint, LO, D) => {
219
+ const logOverride = (key, value) => {
220
+ if (!LO) return value;
221
+ console.warn(`Overriden: ${key}=${value}`);
222
+ return value;
223
+ };
224
+
225
+ function buildPlugin(spec) {
226
+ const plugin = spec;
227
+ plugin.length = spec.mimeTypes.length;
228
+ spec.mimeTypes.forEach((m, i) => {
229
+ plugin[i] = m;
230
+ Object.assign(m, {
231
+ enabledPlugin: plugin,
232
+ });
233
+ });
234
+ delete spec.mimeTypes;
235
+ return plugin;
236
+ }
237
+
238
+ const plugins = {
239
+ length: 4,
240
+ 0: buildPlugin({
241
+ mimeTypes: [{
242
+ type: 'application/x-google-chrome-pdf',
243
+ suffixes: 'pdf',
244
+ description: 'Portable Document Format',
245
+ enabledPlugin: true,
246
+ }],
247
+ name: 'Chrome PDF Plugin',
248
+ description: 'Portable Document Format',
249
+ filename: 'internal-pdf-viewer',
250
+ }),
251
+ 1: buildPlugin({
252
+ mimeTypes: [{
253
+ type: 'application/pdf',
254
+ suffixes: 'pdf',
255
+ description: '',
256
+ extensions: 'pdf',
257
+ enabledPlugin: true,
258
+ }],
259
+ name: 'Chrome PDF Viewer',
260
+ description: '',
261
+ filename: 'mhjfbmdgcfjbbpaeojofohoefgiehjai',
262
+ }),
263
+ 2: buildPlugin({
264
+ mimeTypes: [{
265
+ type: 'application/x-nacl',
266
+ suffixes: '',
267
+ description: 'Native Client Executable',
268
+ enabledPlugin: true,
269
+ }, {
270
+ type: 'application/x-pnacl',
271
+ suffixes: '',
272
+ description: 'Portable Native Client Executable',
273
+ enabledPlugin: true,
274
+ },
275
+ {
276
+ type: 'text/html',
277
+ suffixes: '',
278
+ description: '',
279
+ enabledPlugin: true,
280
+ },
281
+ {
282
+ type: 'application/x-ppapi-vysor',
283
+ suffixes: '',
284
+ description: '',
285
+ enabledPlugin: true,
286
+ },
287
+ {
288
+ type: 'application/x-ppapi-vysor-audio',
289
+ suffixes: '',
290
+ description: '',
291
+ enabledPlugin: true,
292
+ },
293
+ ],
294
+ name: 'Native Client',
295
+ description: '',
296
+ filename: fingerprint.platform === 'Win32' ? 'pepflashplayer.dll' : 'internal-nacl-plugin',
297
+ }),
298
+ 3: buildPlugin({
299
+ mimeTypes: [{
300
+ type: 'application/x-ppapi-widevine-cdm',
301
+ suffixes: '',
302
+ description: 'Widevine Content Decryption Module',
303
+ enabledPlugin: true,
304
+ }],
305
+ name: 'Widevine Content Decryption Module',
306
+ description: 'Enables Widevine licenses for playback of HTML audio/video content. (version: 1.4.9.1070)',
307
+ filename: fingerprint.platform === 'Win32' ? 'widevinecdmadapter.dll' : 'widevinecdmadapter.plugin',
308
+ }),
309
+ };
310
+
311
+ window.screen.__defineGetter__('width', () => logOverride('width', fingerprint.screenWidth));
312
+ window.screen.__defineGetter__('availWidth', () => logOverride('availWidth', fingerprint.screenWidth));
313
+ window.__defineGetter__('innerWidth', () => logOverride('innerWidth', D.width));
314
+ window.__defineGetter__('outerWidth', () => logOverride('outerWidth', D.width));
315
+ window.screen.__defineGetter__('height', () => logOverride('height', fingerprint.screenHeight));
316
+ window.screen.__defineGetter__('availHeight', () => logOverride('availHeight', fingerprint.screenHeight));
317
+ window.__defineGetter__('innerHeight', () => logOverride('innerHeight', D.height - 74));
318
+ window.__defineGetter__('outerHeight', () => logOverride('outerHeight', D.height));
319
+
320
+ window.navigator.__defineGetter__('userAgent', () => logOverride('userAgent', fingerprint.userAgent));
321
+ window.navigator.__defineGetter__('platform', () => logOverride('platform', fingerprint.platform));
322
+ window.navigator.__defineGetter__('appName', () => logOverride('appName', fingerprint.appName));
323
+ window.navigator.__defineGetter__('appVersion', () => logOverride('appVersion', fingerprint.userAgent.substring(fingerprint.userAgent.indexOf('/') + 1, fingerprint.userAgent.length)));
324
+
325
+ const newProto = navigator.__proto__;
326
+ delete newProto.webdriver;
327
+ navigator.__proto__ = newProto
328
+
329
+ window.navigator.__defineGetter__('languages', () => logOverride('languages', ['en-US,en']));
330
+ window.navigator.__defineGetter__('getUserMedia', () => logOverride('getUserMedia', undefined));
331
+ window.navigator.__defineGetter__('webkitGetUserMedia', () => logOverride('webkitGetUserMedia', undefined));
332
+
333
+ // reject webRTC fingerprinting
334
+ window.__defineGetter__('MediaStreamTrack', () => logOverride('MediaStreamTrack', undefined));
335
+ window.__defineGetter__('RTCPeerConnection', () => logOverride('RTCPeerConnection', undefined));
336
+ window.__defineGetter__('RTCSessionDescription', () => logOverride('RTCSessionDescription', undefined));
337
+ window.__defineGetter__('webkitMediaStreamTrack', () => logOverride('webkitMediaStreamTrack', undefined));
338
+ window.__defineGetter__('webkitRTCPeerConnection', () => logOverride('webkitRTCPeerConnection', undefined));
339
+ window.__defineGetter__('webkitRTCSessionDescription', () => logOverride('webkitRTCSessionDescription', undefined));
340
+ window.navigator.__defineGetter__('getUserMedia', () => logOverride('getUserMedia', undefined));
341
+ window.navigator.__defineGetter__('webkitGetUserMedia', () => logOverride('webkitGetUserMedia', undefined));
342
+
343
+ window.navigator.__defineGetter__('plugins', () => logOverride('plugins', plugins));
344
+
345
+
346
+ // handle canvas
347
+ class WebGLRenderingContext {
348
+ constructor(cvs) {
349
+ this.extension = {
350
+ UNMASKED_VENDOR_WEBGL: 37445,
351
+ UNMASKED_RENDERER_WEBGL: 37446,
352
+ };
353
+ this.canvas = cvs;
354
+ this.parameter = '';
355
+ this.viewportWidth = cvs.width;
356
+ this.viewportHeight = cvs.height;
357
+ this.supportedExtensions = ['ANGLE_instanced_arrays', 'EXT_blend_minmax', 'EXT_color_buffer_half_float', 'EXT_frag_depth', 'EXT_shader_texture_lod', 'EXT_texture_filter_anisotropic', 'WEBKIT_EXT_texture_filter_anisotropic', 'EXT_sRGB', 'OES_element_index_uint', 'OES_standard_derivatives', 'OES_texture_float', 'OES_texture_float_linear', 'OES_texture_half_float', 'OES_texture_half_float_linear', 'OES_vertex_array_object', 'WEBGL_color_buffer_float', 'WEBGL_compressed_texture_s3tc', 'WEBKIT_WEBGL_compressed_texture_s3tc', 'WEBGL_compressed_texture_s3tc_srgb', 'WEBGL_debug_renderer_info', 'WEBGL_debug_shaders', 'WEBGL_depth_texture', 'WEBKIT_WEBGL_depth_texture', 'WEBGL_draw_buffers', 'WEBGL_lose_context', 'WEBKIT_WEBGL_lose_context'];
358
+ }
359
+
360
+ getExtension() {
361
+ return this.extension;
362
+ }
363
+
364
+ getParameter() {
365
+ return this.extension;
366
+ }
367
+
368
+ getSupportedExtensions() {
369
+ return this.supportedExtensions;
370
+ }
371
+ }
372
+
373
+ const canvas = document.createElement('canvas');
374
+ const canvasProto = Object.getPrototypeOf(canvas);
375
+ const origGetContext = canvasProto.getContext;
376
+ canvasProto.getContext = function getContext(...args) {
377
+ const context = origGetContext && (origGetContext.call(this, ...args) || origGetContext.call(this, args[0]));
378
+ if (!context) {
379
+ logOverride('canvas.getContext', 'new WebGLRenderingContext()');
380
+ return new WebGLRenderingContext(this);
381
+ }
382
+ return context;
383
+ };
384
+
385
+ canvasProto.getContext.toString = canvasProto.getContext.toString();
386
+
387
+ function hookPrototypeMethods(prefix, object) {
388
+ if (!object) return;
389
+ const originals = {};
390
+ const prototype = Object.getPrototypeOf(object);
391
+ Object
392
+ .getOwnPropertyNames(prototype)
393
+ .filter((n) => {
394
+ try {
395
+ return typeof prototype[n] === 'function';
396
+ } catch (error) {
397
+ return false;
398
+ }
399
+ })
400
+ .forEach((n) => {
401
+ originals[n] = prototype[n];
402
+ prototype[n] = function fn(...args) {
403
+ if (prefix === '2d' && (n === 'strokeText' || n === 'fillText')) {
404
+ const temp = Array.from(args);
405
+ temp[0] = fingerprint.BUID;
406
+ temp[1] = Math.max(0, temp[1] - 2);
407
+ temp[2] = Math.max(0, temp[2] - 2);
408
+ originals[n].call(this, ...temp);
409
+ }
410
+
411
+ const result = originals[n].call(this, ...args);
412
+ if (LO) {
413
+ let jsonResult;
414
+ try {
415
+ jsonResult = JSON.stringify(result);
416
+ } catch (e) {}
417
+ console.warn('function called', prefix, n, JSON.stringify(args), 'result:', result, jsonResult, `${result}`);
418
+ }
419
+ return result;
420
+ };
421
+ });
422
+ }
423
+
424
+ const gls = [];
425
+ try {
426
+ gls.push(document.createElement('canvas').getContext('webgl'));
427
+ gls.push(document.createElement('canvas').getContext('experimental-webgl'));
428
+ } catch (e) {}
429
+
430
+ gls.forEach((gl) => {
431
+ const glProto = Object.getPrototypeOf(gl);
432
+ const origGetParameter = glProto.getParameter;
433
+ const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
434
+ if (gl) {
435
+ glProto.getParameter = function getParameter(...args) {
436
+ if (args[0] === debugInfo.UNMASKED_VENDOR_WEBGL) return logOverride('gl.getParameter.UNMASKED_VENDOR_WEBGL', fingerprint.WEBGL_VENDOR);
437
+ if (args[0] === debugInfo.UNMASKED_RENDERER_WEBGL) return logOverride('gl.getParameter.UNMASKED_RENDERER_WEBGL', fingerprint.WEBGL_RENDERER);
438
+ if (args[0] === 33901) return new Float32Array([1, 8191]);
439
+ if (args[0] === 3386) return new Int32Array([16384, 16384]);
440
+ if (args[0] === 35661) return 80;
441
+ if (args[0] === 34076) return 16384;
442
+ if (args[0] === 36349) return 1024;
443
+ if (args[0] === 34024) return 16384;
444
+ if (args[0] === 3379) return 16384;
445
+ if (args[0] === 34921) return 16;
446
+ if (args[0] === 36347) return 1024;
447
+
448
+ return origGetParameter.call(this, ...args);
449
+ };
450
+ }
451
+ });
452
+
453
+ hookPrototypeMethods('webgl', document.createElement('canvas').getContext('webgl'));
454
+ hookPrototypeMethods('experimental-webgl', document.createElement('canvas').getContext('experimental-webgl'));
455
+ hookPrototypeMethods('2d', document.createElement('canvas').getContext('2d'));
456
+ hookPrototypeMethods('canvas', canvas);
457
+
458
+ hookPrototypeMethods('screen', window.screen);
459
+ hookPrototypeMethods('navigator', window.navigator);
460
+ hookPrototypeMethods('history', window.history);
461
+ }, fingerprint, LOG_OVERRIDE, DIMENSION);
462
+
463
+ // emulate permissions
464
+ await page.addInitScript(() => {
465
+ const originalQuery = window.navigator.permissions.query;
466
+ window.navigator.permissions.__proto__.query = (parameters) => (parameters.name === 'notifications' ?
467
+ Promise.resolve({
468
+ state: Notification.permission
469
+ }) :
470
+ originalQuery(parameters));
471
+
472
+ const oldCall = Function.prototype.call;
473
+
474
+ function call() {
475
+ return oldCall.apply(this, arguments);
476
+ }
477
+ Function.prototype.call = call;
478
+
479
+ const nativeToStringFunctionString = Error.toString().replace(
480
+ /Error/g,
481
+ 'toString',
482
+ );
483
+ const oldToString = Function.prototype.toString;
484
+
485
+ function functionToString() {
486
+ if (this === window.navigator.permissions.query) {
487
+ return 'function query() { [native code] }';
488
+ }
489
+ if (this === functionToString) {
490
+ return nativeToStringFunctionString;
491
+ }
492
+ return oldCall.call(oldToString, this);
493
+ }
494
+ Function.prototype.toString = functionToString;
495
+ });
496
+
497
+ // must to hook getters
498
+ await page.goto('about:blank');
499
+
500
+ await page.setExtraHTTPHeaders({
501
+ 'Accept-Language': 'en-US,en;q=0.9',
502
+ 'Accept-Encoding': 'gzip, deflate, br',
503
+ });
504
+
505
+ await page.setViewport(DIMENSION);
506
+ }
507
+
508
+ const args = [
509
+ '--no-sandbox',
510
+ '--remote-debugging-port=9222',
511
+ '--disable-setuid-sandbox',
512
+ '--ignore-certificate-errors',
513
+ '--disk-cache-size=1',
514
+ '--disable-infobars',
515
+ '--disable-blink-features=AutomationControlled'
516
+ ];
517
+
518
+ const browser = await chromium.launchPersistentContext('', {
519
+ headless: false,
520
+ bypassCSP: true,
521
+ ignoreHTTPSErrors: true,
522
+ args: args,
523
+ timezoneId: 'America/Los_Angeles',
524
+ });
525
+
526
+ // generate a fingerprint
527
+ const fingerprint = await getBrowserfingerprint(uuidv4());
528
+ let page = await browser.newPage();
529
+
530
+ // "cloak" our page with evasions
531
+ await cloak(page, fingerprint);
532
+
533
+
534
+
535
+
536
+ //await context.route("**/*.{png,jpg,jpeg,css,js}", route => route.abort());
537
+ await page.goto(url);
538
+
539
+ await setTimeout(2000);
540
+
541
+ // let id = crypto.randomUUID();
542
+ // let path = `/code/${id}.png`;
543
+ // await page.screenshot({ path, fullPage: true });
544
+
545
+ const buffer = await page.screenshot({fullPage: true});
546
+
547
+ await page.close();
548
+ await browser.close();
549
+
550
+ return buffer;
551
+ }
552
+
553
+
554
+
555
+
556
+
557
  const server = http.createServer(async function(req, res) {
558
  const {query, pathname} = url.parse(req.url, true);
559
 
560
+ console.log(req.url, new Date());
561
 
562
  res.setHeader('Access-Control-Allow-Origin', '*')
563
 
 
580
  // res.writeHead(200,{'Content-type':'image/png'});
581
  // readStream.pipe(res);
582
  // res.end();
583
+
584
+ } else if (pathname == '/bot') {
585
+ let buffer = await test_bot(_url);
586
+
587
+ res.writeHead(200,{'Content-type':'image/png'});
588
+ res.end(buffer);
589
+
590
  } else if (pathname == '/evaluate') {
591
  const buffers = [];
592
  for await (const chunk of req) {