Talk:Metadata Block
From GreaseSpot
NOTE: This feature is not released yet. This is a draft of some documentation for this feature.
A page titled document-start may be necessary for full details. Other documentation of this feature:
http://code.google.com/chrome/extensions/content_scripts.html
http://www.chromium.org/developers/design-documents/user-scripts
Please note there is a discrepancy between the above two documents whether to use an underscore or a dash, however we are using a dash since this is the syntax for userscripts.
This documentation is based on the test script available here: http://gist.github.com/418707
[edit] @run-at
Example:
// @run-at document-start
This indicates when the script should be injected into the page. By default scripts are run at document-end occurring at DOMContentLoaded. Use document-start to start running scripts or apply styles before anything has downloaded.
You may have to attach your own DOMContentLoaded listener to show the finished result or run scripts that depend on page elements being accessible.
document.addEventListener('DOMContentLoaded', function(){
//page has fully loaded, run interactive scripts here
}, true);
To detect if your script is currently running in a document-start compatible version of greasemonkey use the following logic:
//document.body is null at document-start var ranAtDocumentStart = document.body == null;
A typical use of document-start involves using GM_addStyle to hide the document body, allowing you to manipulate the page, and then show the result only when the page is loaded and the modifications have been applied. Another use involves listening for the DOMNodeInserted event and reacting as elements are added to the page.

