tor-browser

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

bug1847971-ebay.com-barcode-scanner.js (1542B)


      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 1847971 - ebay.com listings page
      9 *
     10 * eBay does not show the barcode scanner option on Firefox on Android,
     11 * though it seems to work. It uses a server-side check to tell itself
     12 * to not enable the scanner feature, so rather than pretend to be Chrome
     13 * entirely, we carefully change `barcodeEnabled` from `false` to `true`.
     14 */
     15 
     16 /* globals exportFunction */
     17 
     18 const ENABLED_MESSAGE =
     19  "The barcode scanner feature has been force-enabled. See https://bugzilla.mozilla.org/show_bug.cgi?id=1847971 for details.";
     20 
     21 let value = undefined;
     22 
     23 function check(obj) {
     24  if (obj === null) {
     25    return false;
     26  }
     27  if (Array.isArray(obj)) {
     28    for (const v of obj) {
     29      if (check(v)) {
     30        return true;
     31      }
     32    }
     33    return false;
     34  }
     35  if (typeof obj === "object") {
     36    if ("barcodeEnabled" in obj) {
     37      obj.barcodeEnabled = true;
     38      return true;
     39    }
     40    for (const v of Object.values(obj)) {
     41      if (check(v)) {
     42        return true;
     43      }
     44    }
     45  }
     46  return false;
     47 }
     48 
     49 Object.defineProperty(window.wrappedJSObject, "$feprelist_C", {
     50  configurable: true,
     51 
     52  get: exportFunction(function () {
     53    return value;
     54  }, window),
     55 
     56  set: exportFunction(function (v) {
     57    try {
     58      if (check(v)) {
     59        console.info(ENABLED_MESSAGE);
     60      }
     61    } catch (_) {}
     62    value = v;
     63  }, window),
     64 });