how can i use a chrome extension content script to inject html into a page at startup

自作多情 提交于 2019-12-03 03:55:01

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!