Scriptlets icon indicating copy to clipboard operation
Scriptlets copied to clipboard

Add new scriptlet to remove parameters from URL

Open AdamWr opened this issue 2 years ago • 0 comments

Sometimes to block some (usually video) ads a rule with $removeparam modifier is used, for example here - https://github.com/AdguardTeam/AdguardFilters/issues/153758 (roosterteeth.com)

The problem is that these kind of rules are not supported by iOS/Safari, so maybe we could add a scriptlet which will remove parameters from fetch and XMLHttpRequest. For example, something like (basing on roosterteeth.com case):

(function () {
  const removeParam = (parameter, requestURL) => {
    const wrapper = (target, thisArg, args) => {
      if (args[0] && args[1] && args[1].includes(requestURL)) {
        const url = new URL(args[1]);
        url.searchParams.delete(parameter);
        args[1] = url;
      }
      return Reflect.apply(target, thisArg, args);
    };
    const handler = {
      apply: wrapper
    };
    window.XMLHttpRequest.prototype.open = new Proxy(window.XMLHttpRequest.prototype.open, handler);
  };
  removeParam('ad_config_id', 'brightcove.com/playback/');
})();

Rule:

roosterteeth.com#%#((e,t)=>{const o={apply:(o,n,p)=>{if(p[0]&&p[1]&&p[1].includes(t)){const t=new URL(p[1]);t.searchParams.delete(e),p[1]=t}return Reflect.apply(o,n,p)}};window.XMLHttpRequest.prototype.open=new Proxy(window.XMLHttpRequest.prototype.open,o)})("ad_config_id","brightcove.com/playback/");

By the way, if I'm not wrong, Adblock Plus has a snippet for removing parameters too (strip-fetch-query-parameter).

AdamWr avatar Jun 16 '23 05:06 AdamWr