tor-browser

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

adnexus-prebid.js (1593B)


      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 1694401 - Shim Prebid.js
      9 *
     10 * Some sites rely on prebid.js to place content, perhaps in conjunction with
     11 * other services like Google Publisher Tags and Amazon TAM. This shim prevents
     12 * site breakage like image galleries breaking as the user browsers them, by
     13 * allowing the content placement to succeed.
     14 */
     15 
     16 if (!window.pbjs?.requestBids) {
     17  const que = window.pbjs?.que || [];
     18  const cmd = window.pbjs?.cmd || [];
     19  const adUnits = window.pbjs?.adUnits || [];
     20 
     21  window.pbjs = {
     22    adUnits,
     23    addAdUnits(arr) {
     24      if (!Array.isArray(arr)) {
     25        arr = [arr];
     26      }
     27      adUnits.push(arr);
     28    },
     29    cmd,
     30    offEvent() {},
     31    que,
     32    refreshAds() {},
     33    removeAdUnit(codes) {
     34      if (!Array.isArray(codes)) {
     35        codes = [codes];
     36      }
     37      for (const code of codes) {
     38        for (let i = adUnits.length - 1; i >= 0; i--) {
     39          if (adUnits[i].code === code) {
     40            adUnits.splice(i, 1);
     41          }
     42        }
     43      }
     44    },
     45    renderAd() {},
     46    requestBids(params) {
     47      params?.bidsBackHandler?.();
     48    },
     49    setConfig() {},
     50    setTargetingForGPTAsync() {},
     51  };
     52 
     53  const push = function (fn) {
     54    if (typeof fn === "function") {
     55      try {
     56        fn();
     57      } catch (e) {
     58        console.trace(e);
     59      }
     60    }
     61  };
     62 
     63  que.push = push;
     64  cmd.push = push;
     65 
     66  que.forEach(push);
     67  cmd.forEach(push);
     68 }