AdguardTeam / Scriptlets

AdGuard scriptlets library
GNU General Public License v3.0
148 stars 29 forks source link

Add a redirect resource for `prebid.js` #177

Closed AdamWr closed 2 years ago

AdamWr commented 2 years ago

Sometimes websites are broken if prebid.js is blocked. At the moment, I found only two cases, but maybe it would be a good idea to fix it anyway.

Steps to reproduce:

  1. Add these rules:

    securenetsystems.net#@%#(function(){var a={setConfig:function(){},aliasBidder:function(){},removeAdUnit:function(){},que:[push=function(){}]};window.pbjs=a})();
    atv.com.tr#@%#//scriptlet("set-constant", "HBiddings.vastUrl", "")
    ||tmgrup.com.tr/bd/hb/prebid.js$important
    ||securenetsystems.net/cirruscontent/js/prebid.js$important
  2. Navigate to - https://www.atv.com.tr/destan/6-bolum-2-fragman/izle 2.1. Try to watch video, it doesn't work if prebid.js is blocked. Related to - https://github.com/AdguardTeam/AdguardFilters/issues/103996#issuecomment-1006259700

  3. Navigate to - https://streamdb0web.securenetsystems.net/cirruscontent/DEMOSTN 3.1. Click on an "Artist bio" button (screenshots below), it doesn't work if prebid.js is blocked. Related to - https://github.com/AdguardTeam/AdguardFilters/issues/100820

Screenshots ![image](https://user-images.githubusercontent.com/29142494/148657501-0f58025e-1964-406b-be22-a00ea5153ecb.png) ![image](https://user-images.githubusercontent.com/29142494/148657502-03f156e7-7662-4c99-902d-a138e9840745.png)

Something like this should fix both issues:

(function () {
  const pushFunction = function (arg) {
    if ("function" === typeof arg) {
      try {
        arg.call();
      } catch (ex) {}
    }
  };

  const pbjsWrapper = {
    addAdUnits: function () {},
    adServers: {
      dfp: {
        buildVideoUrl: function () {
          return ""; // returns ad URL - https://docs.prebid.org/dev-docs/publisher-api-reference/adServers.dfp.buildVideoUrl.html
        }
      }
    },
    adUnits: [],
    aliasBidder: function () {},
    cmd: [],
    enableAnalytics: function () {},
    getHighestCpmBids: function () {
      return [];
    },
    libLoaded: true,
    que: [],
    requestBids: function (arg) {
      if (arg instanceof Object && arg.bidsBackHandler) {
        try {
          arg.bidsBackHandler.call(); // https://docs.prebid.org/dev-docs/publisher-api-reference/requestBids.html
        } catch (ex) {}
      }
    },
    removeAdUnit: function () {},
    setBidderConfig: function () {},
    setConfig: function () {},
    setTargetingForGPTAsync: function () {}
  };
  pbjsWrapper.cmd.push = pushFunction;
  pbjsWrapper.que.push = pushFunction;

  window.pbjs = pbjsWrapper;
})();

I guess that it may needs additional tweaks, but additional real cases could be required, I think.

https://docs.prebid.org/overview/intro.html

stanislav-atr commented 2 years ago

Some legacy versions of prebid.js will be solved in this issue.