Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one have Greasemonkey run before *anything* else in the page?

Tags:

Is it possible to have Greasemonkey scripts run before anything else on the page?

I'm aware of @run-at document-start, but this appears to run immediately after the <HTML> tag. Normally this isn't a problem, but if the page is misformatted as in the example below, there doesn't seem to be anything I can do.

I'd appreciate any suggestions or ideas. Thanks!

<script>alert('This is an annoying message.');</script>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
        <HEAD>
...etc...
like image 668
anschauung Avatar asked Apr 02 '09 03:04

anschauung


1 Answers

Actually, @run-at document-start does pretty much run the GM script before anything from the page.

In your case, the following code will work in conjunction with @run-at document-start:

_oldAlert           = alert;
unsafeWindow.alert  = function () {};

/*-- Optionally, wait for the DOM, then set an onload handler to restore
    alert().
*/
like image 194
Brock Adams Avatar answered Oct 12 '22 01:10

Brock Adams