tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

patch.mjs (1809B)


      1 /**
      2 * @license
      3 * Copyright 2024 Google Inc.
      4 * SPDX-License-Identifier: Apache-2.0
      5 */
      6 import fs from 'fs';
      7 
      8 const genJs = process.argv[2];
      9 const genTypes = process.argv[3];
     10 const inputTypes = process.argv[4];
     11 
     12 let file = fs.readFileSync(genJs, 'utf-8');
     13 
     14 file = file.replaceAll('__proto__: [],', '');
     15 file = file.replaceAll('__proto__: null,', '');
     16 file = file.replaceAll('__proto__: [],', '');
     17 
     18 file = file.replaceAll('__proto__: []', '');
     19 file = file.replaceAll('__proto__: null', '');
     20 file = file.replaceAll('d2.__proto__ = b2;', '');
     21 file = file.replaceAll('__proto__: []', '');
     22 
     23 file = file.replaceAll('fn = new Function(`return ${functionValue}`)();', '');
     24 file = file.replaceAll('new Function(`(${value})`);', '// stripped');
     25 file = file.replaceAll(
     26  `return await this.evaluate(html => {
     27          document.open();
     28          document.write(html);
     29          document.close();
     30        }, content);`,
     31  'throw new Error("unsupported")',
     32 );
     33 file = file.replaceAll('link.href = url;', 'throw new Error("unsupported")');
     34 file = file.replaceAll('script.src = url;', 'throw new Error("unsupported")');
     35 
     36 fs.writeFileSync(genJs, file);
     37 
     38 fs.copyFileSync(inputTypes, genTypes);
     39 
     40 file = fs.readFileSync(genTypes, 'utf-8');
     41 
     42 file = file.replaceAll('#private;', '');
     43 
     44 file = file.replaceAll(
     45  `import { Session } from 'chromium-bidi/lib/cjs/protocol/protocol.js';`,
     46  'type Session = any;',
     47 );
     48 file = file.replaceAll(
     49  `import type { ParseSelector } from 'typed-query-selector/parser.js';`,
     50  'type ParseSelector<T extends string> = any;',
     51 );
     52 
     53 file = file.replaceAll(
     54  `export declare type SupportedWebDriverCapability = Exclude<Session.CapabilityRequest, 'unhandledPromptBehavior' | 'acceptInsecureCerts'>;`,
     55  'export declare type SupportedWebDriverCapability = any;',
     56 );
     57 
     58 fs.writeFileSync(genTypes, file);