MDN wants to learn about developers like you:





框架脚本的全局是 ContentFrameMessageManager,提供下列环境:

content The DOM window of the content loaded in the browser. may be null (see below)
docShell The nsIDocShell associated with the browser.
addEventListener() Listen to events from content.
removeEventListener() Stop listening to events from content.
addMessageListener() Listen to messages from chrome.
removeMessageListener() Stop listening to messages from chrome.
sendAsyncMessage() Send an asynchronous message to chrome.
sendSyncMessage() Send a synchronous message to chrome.
dump() Print a message to the console.
atob() Base64 decode.
btoa() Base64 encode.
Components The usual Components object.

特别注意,框架脚本使用 content 访问 DOM 窗口,而不是 window

// frame script
var links = content.document.getElementsByTagName("a");

All the frame scripts running in a tab share this global. However, any top-level variables defined by a script are not stored on the global: instead, top-level variables are stored in a special per-script object that delegates to the per-tab global. This means you don't have to worry about global variables you define conflicting with global variables defined by another frame script. You can still access the global directly via this.

框架脚本使用系统主体运行。如果你想使用其他主题,可以使用 Sandbox

Frame scripts run with system privileges and have access to the Components object, enabling them to use XPCOM objects and JSMs. However, some APIs  that work in the chrome process will not work in a frame script. See Limitations of frame scripts for more details.


Besides the regular DOM events being captured/bubbling up from content the current content object the following additional events get fired in a frame script environment:


Fires when the frame script environment is shut down, i.e. when a tab gets closed.

If you use a capturing event listener on the ContentFrameMessageManager, you should verify that its is set to the ContentFrameMessageManager global object in order to avoid handling unload events from content.


Fires when a new content object is created.

This can be used if a framescript needs to interact with individual DOM windows instead of simply listening for events bubbling up from content.
Another use is to interact with the content very early in the page load process, long before DOMContentLoaded event is fired.



 此页面的贡献者: yfdyh000
 最后编辑者: yfdyh000,