Friday, 18 December 2020

How to override a site's variable with Tampermonkey?

I am trying to override a function set up by a website (window.jsl.dh). This is the declaration:

window.jsl = window.jsl || {};
window.jsl.dh = window.jsl.dh || function(i, c, d) { blabla }

I want to assign dh to a dud function, but after banging my head for a while, I don't know what's real anymore. I've tried creating a bogus dh() and Object.freeze(window.jsl), using a Proxy, adding setters, cheering up my laptop... no luck. Whatever I do, that piece of code seems to run unimpeded, and the dh() function always gets assigned and running without an issue.

This is the code:

  window.jsl = window.jsl || {};
  window.jsl.dh = function () {
    console.log('Called the dud');
  };
  Object.freeze(window.jsl);

If I set a breakpoint after the TM script run, but before the site's declaration and manually enter the same code in the console, it works.

Thinking this may be a sandboxing issue, I've messed with every @grant and script injection method under the sun —also different timings with @run-at.

Can't see why it's not working on its own, and I run out of ideas.



from How to override a site's variable with Tampermonkey?

No comments:

Post a Comment