Scriptlets icon indicating copy to clipboard operation
Scriptlets copied to clipboard

Add redirect resource for FreeWheel AdManager.js

Open AdamWr opened this issue 1 year ago • 0 comments

Related to this issue - https://github.com/AdguardTeam/AdguardFilters/issues/172374

Video player is broken if https://mssl.fwmrm.net/libs/adm/6.55.0/AdManager.js is blocked.

It seems that something like this:

Code:
(() => {
  const eventsMap = new Map();
  const noopFunc = function () {};
  const noopThis = function () {
    return this;
  };
  const adManagerFunc = noopFunc;
  adManagerFunc.prototype.dispose = noopFunc;
  adManagerFunc.prototype.setNetwork = noopFunc;
  adManagerFunc.prototype.resize = noopFunc;
  adManagerFunc.prototype.setServer = noopFunc;
  adManagerFunc.prototype.setLogLevel = noopFunc;
  adManagerFunc.prototype.newContext = noopThis;
  adManagerFunc.prototype.setParameter = noopFunc;
  adManagerFunc.prototype.addEventListener = function (type, callback) {
    if (type) {
      console.debug(`Type: ${type}, callback: ${callback}`);
      // debugger;
      eventsMap.set(type, callback);
    }
  };
  adManagerFunc.prototype.removeEventListener = noopFunc;
  adManagerFunc.prototype.setProfile = noopFunc;
  adManagerFunc.prototype.setCapability = noopFunc;
  adManagerFunc.prototype.setVideoAsset = noopFunc;
  adManagerFunc.prototype.setSiteSection = noopFunc;
  adManagerFunc.prototype.addKeyValue = noopFunc;
  adManagerFunc.prototype.addTemporalSlot = noopFunc;
  adManagerFunc.prototype.registerCustomPlayer = noopFunc;
  adManagerFunc.prototype.setVideoDisplaySize = noopFunc;
  adManagerFunc.prototype.setContentVideoElement = noopFunc;
  adManagerFunc.prototype.registerVideoDisplayBase = noopFunc;
  adManagerFunc.prototype.submitRequest = function () {
    const event = {
      type: tv.freewheel.SDK.EVENT_SLOT_ENDED
    };
    const func = eventsMap.get('EVENT_SLOT_ENDED');
    // debugger;
    if (func) {
      setTimeout(() => {
        try {
          func(event);
        } catch (ex) {
          console.error(ex);
        }
      }, 1);
    }
  };
  window.tv = {
    freewheel: {
      SDK: {
        Ad: noopFunc,
        AdManager: adManagerFunc,
        AdListener: noopFunc,
        _instanceQueue: {},
        setLogLevel: noopFunc,
        EVENT_SLOT_ENDED: 'EVENT_SLOT_ENDED'
      }
    }
  };
})();

Rule:

southparkstudios.com#%#(()=>{const e=new Map,t=function(){},o=t;o.prototype.dispose=t,o.prototype.setNetwork=t,o.prototype.resize=t,o.prototype.setServer=t,o.prototype.setLogLevel=t,o.prototype.newContext=function(){return this},o.prototype.setParameter=t,o.prototype.addEventListener=function(t,o){t&&(console.debug(`Type: ${t}, callback: ${o}`),e.set(t,o))},o.prototype.removeEventListener=t,o.prototype.setProfile=t,o.prototype.setCapability=t,o.prototype.setVideoAsset=t,o.prototype.setSiteSection=t,o.prototype.addKeyValue=t,o.prototype.addTemporalSlot=t,o.prototype.registerCustomPlayer=t,o.prototype.setVideoDisplaySize=t,o.prototype.setContentVideoElement=t,o.prototype.registerVideoDisplayBase=t,o.prototype.submitRequest=function(){const t={type:tv.freewheel.SDK.EVENT_SLOT_ENDED},o=e.get("EVENT_SLOT_ENDED");o&&setTimeout((()=>{try{o(t)}catch(e){console.error(e)}}),1)},window.tv={freewheel:{SDK:{Ad:t,AdManager:o,AdListener:t,_instanceQueue:{},setLogLevel:t,EVENT_SLOT_ENDED:"EVENT_SLOT_ENDED"}}}})();

fixes issue with video player.

I suppose that it might requires more tweaks, but maybe we could consider to add redirect resource for mssl.fwmrm.net/libs/adm/6.55.0/AdManager.js.

AdamWr avatar Feb 07 '24 10:02 AdamWr