1

I'm looking to block an alert on a website via a userscript loaded in via Tampermonkey (or a similar extension/plugin).

The code for said alert is triggered on if(window.parent==window){alert()} and is contained in a .js file that the HTML page loads in via <script>, so that complicates matters further.

I've tried a simple window.alert = function() { /* NOTHING */ }; as well as if(window.parent==window){}; but to no avail. (I'd read that you 'replace' the original code by adding another statement, but I'm guessing that doesn't apply to userscripts in relation to the webpages they're loaded into.)

I'm guessing that a more practical solution would be to fake a parent window as not to trigger the alert, but I couldn't manage to get that to work either.

How would I go about doing this, if this is possible at all?

Sluimerstand
  • 43
  • 1
  • 1
  • 4
  • Are you able to run code *before* the alert script runs (such as with `@run-at document-start`)? If not, it may not be possible with a Tampermonkey userscript. (*might* be possible with an [extension](https://stackoverflow.com/questions/2963677/can-i-prevent-an-alert-with-a-google-chrome-extension) instead, but I'm not sure how soon an extension code can run) – CertainPerformance Mar 06 '19 at 22:01
  • `window.alert = function() { /* NOTHING */ }` was a good approach... But if it does not work, I guess it simply executes before the user script is loaded. – Louys Patrice Bessette Mar 06 '19 at 22:01
  • Look [here](https://groups.google.com/d/msg/chromium-discuss/ExF_VjrqBuY/Ww3-144KsJsJ) and see if it works for you ;) – Louys Patrice Bessette Mar 06 '19 at 22:13

0 Answers0