tor-browser

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

bug1898952-digits.t-mobile.com.js (1706B)


      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 1898952 - Spoof navigator.userAgentData for digits.t-mobile.com
      9 * Webcompat issue #119767 - https://webcompat.com/issues/119767
     10 *
     11 * The site blocks Firefox and Safari, reading info from userAgentData.
     12 */
     13 
     14 /* globals exportFunction, cloneInto */
     15 
     16 if (!navigator.userAgentData) {
     17  console.info(
     18    "navigator.userAgentData has been overridden for compatibility reasons. See https://webcompat.com/issues/119767 for details."
     19  );
     20 
     21  const ua = navigator.userAgent;
     22  const mobile = ua.includes("Mobile") || ua.includes("Tablet");
     23 
     24  // Very roughly matches Chromium's GetPlatformForUAMetadata()
     25  let platform = "Linux";
     26  if (mobile) {
     27    platform = "Android";
     28  } else if (navigator.platform.startsWith("Win")) {
     29    platform = "Windows";
     30  } else if (navigator.platform.startsWith("Mac")) {
     31    platform = "macOS";
     32  }
     33 
     34  const version = (ua.match(/Firefox\/([0-9.]+)/) || ["", "58.0"])[1];
     35 
     36  // These match Chrome's output as of version 126.
     37  const brands = [
     38    {
     39      brand: "Not/A)Brand",
     40      version: "8",
     41    },
     42    {
     43      brand: "Chromium",
     44      version,
     45    },
     46    {
     47      brand: "Google Chrome",
     48      version,
     49    },
     50  ];
     51 
     52  const userAgentData = cloneInto(
     53    {
     54      brands,
     55      mobile,
     56      platform,
     57    },
     58    window
     59  );
     60 
     61  Object.defineProperty(window.navigator.wrappedJSObject, "userAgentData", {
     62    get: exportFunction(function () {
     63      return userAgentData;
     64    }, window),
     65 
     66    set: exportFunction(function () {}, window),
     67  });
     68 }