Chrome Extension 开发总结

Chrome Extension中的Javascript分三大类:

(Extendsion code更新后需要删除插件后再加载,其它两个需要刷新插件)

Extension code

Full access to all permitted chrome.* APIs.This includes the background page, and all pages which have direct access to it via chrome.extension.getBackgroundPage(), such as the browser pop-ups. Content scripts

(via the manifest file or chrome.tabs.executeScript) – Partial access to some of the chrome APIs, full access to the page’s DOM (not to any of the window objects, including frames).
Content scripts run in a scope between the extension and the page. The global window object of a Content script is distinct from the page/extension’s global namespace.

Injected scripts

(via this method in a Content script) – Full access to all properties in the page. No access to any of the chrome.* APIs.
Injected scripts behave as if they were included by the page itself, and are not connected to the extension in any way. See this post to learn more information on the various injection methods.

To send a message from the injected script to the content script, events have to be used. See this answer for an example. Note: Message transported within an extension from one context to another are automatically (JSON)-serialised and parsed.

Content Script向Injected Script发送Message时Event貌似只能是:RW759_connectExtension ?

Leave a Reply