tor-browser

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

bug1457335-histography.io-ua-change.js (1176B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Bug 1457335 - histography.io - Override UA & navigator.vendor
      9 * WebCompat issue #1804 - https://webcompat.com/issues/1804
     10 *
     11 * This site is using a strict matching of navigator.userAgent and
     12 * navigator.vendor to allow access for Safari or Chrome. Here, we set the
     13 * values appropriately so we get recognized as Chrome.
     14 */
     15 
     16 /* globals exportFunction */
     17 
     18 console.info(
     19  "The user agent has been overridden for compatibility reasons. See https://webcompat.com/issues/1804 for details."
     20 );
     21 
     22 const CHROME_UA = navigator.userAgent + " Chrome for WebCompat";
     23 
     24 const nav = Object.getPrototypeOf(navigator.wrappedJSObject);
     25 
     26 const ua = Object.getOwnPropertyDescriptor(nav, "userAgent");
     27 ua.get = exportFunction(() => CHROME_UA, window);
     28 Object.defineProperty(nav, "userAgent", ua);
     29 
     30 const vendor = Object.getOwnPropertyDescriptor(nav, "vendor");
     31 vendor.get = exportFunction(() => "Google Inc.", window);
     32 Object.defineProperty(nav, "vendor", vendor);