Skip to content Skip to sidebar Skip to footer

Window.load Doesn't Fire Always On Chrome?

I have this userscript: // ==UserScript== // @name test // @namespace test // @description show's an alert on load // @include http://* // @include https

Solution 1:

The cause of the problem is that the Content script is sometimes executed when the document has already fully loaded. This is illustrated using the following Content script ("User Script"):

// ==UserScript==// @name          Test// @namespace     Test// @include       *// ==/UserScript==window.addEventListener('load', function(){alert("loaded");}, false);
alert(document.readyState);   // When this prints "complete", onload never runs

To solve the issue, use the @run-at document-start meta-rule, which causes the script to execute before the document is created:

...
// @run-at   document-start// ==/UserScript==

Solution 2:

This call may be being loaded too late on the page. Add this code to the very top of the page and see if that fixes it.

If that isn't it please post some additional information. (Where the call is being made? Some more information on the page? Is this being called from an external .js file?)

Post a Comment for "Window.load Doesn't Fire Always On Chrome?"