这篇翻译不完整。请帮忙从英语翻译这篇文章。
框架脚本的全局是 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:
unload |
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 |
DOMWindowCreated |
Fires when a new |