美文网首页
content script 的run_at

content script 的run_at

作者: 9b559869875b | 来源:发表于2017-11-16 12:02 被阅读18次

    https://developer.chrome.com/extensions/content_scripts

    run_at  string类型,有3种选择

    Can be "document_start", "document_end", or "document_idle". Defaults to "document_idle".

    In the case of "document_start", the files are injected after any files from css, but before any other DOM is constructed or any other script is run.

    In the case of "document_end", the files are injected immediately after the DOM is complete, but before sub resources like images and frames have loaded.

    In the case of "document_idle", the browser chooses a time to inject scripts between "document_end" and immediately after the window.onload event fires. The exact moment of injection depends on how complex the document is and how long it is taking to load, and is optimized for page load speed.

    注意了:

    Note: With "document_idle", content scripts may not necessarily receive the window.onload event, because they may run after it has already fired. In most cases, listening for the onloadevent is unnecessary for content scripts running at "document_idle" because they are guaranteed to run after the DOM is complete. If your script definitely needs to run after window.onload, you can check if onload has already fired by using the document.readyState property.

    相关文章

      网友评论

          本文标题:content script 的run_at

          本文链接:https://www.haomeiwen.com/subject/slrlvxtx.html