i want to create an extension to inject html into every page as soon as it loads up. I am familiar with teh manifest.json rules for this as well as how to run a content script. The problem I'm currently having is the content script in开发者_如何转开发jects the html after the web page has loaded which is a bit disruptive. I would like to load it as soon as the window is open so it is injected and then the webpage loads as well. Can you help?
Just to be clear here, "loads up" means "starts loading," right? And when you say you're familiar with the manifest.json, you mean you're familiar with the permissions necessary and how to specify which pages and which script to run? Because I think what you're looking for is the run_at
property of content_scripts
in your manifest.json:
http://code.google.com/chrome/extensions/content_scripts.html#registration
{
// other stuff
"content_scripts": [{
"matches": ["http://*/*"],
"js": ["content.js"],
"run_at": "document_start"
}],
// other stuff
}
That forces your code to execute before the DOM loads in every page. Note that this can be complex because your extension may fail to create HTML since, of course, the DOM hasn't yet loaded. If you'd like your script to fire just a bit earlier than its default "document_idle"
, use "document_end"
instead.
精彩评论