Search code examples
javascriptgreasemonkey

greasemonkey: stop embedded JS from running


A page has the following in the html:

<script type="text/javascript">
  // some code
</script>

My greasemonkey script needs to prevent that script from running. How can I do this?


Update: I understand that in the general case this is impossible. However, in my specific case, I may have a loophole?

<script type="text/javascript">
  if (!window.devicePixelRatio) {
    // some code that I -don't- want to be run, regardless of the browser
  }
</script>

Is there some way I can define window.devicePixelRatio before the embedded script runs?


Solution

  • User scripts run after the page is loaded, so you aren't able to.

    Unless, the code uses the "onload" event.

    User scripts are executed after the DOM is fully loaded, but before onload occurs. This means that your scripts can begin immediately and don't need to wait for onload.