非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。
见 bug 1318532 for exposing this API to WebExtensions in Firefox .
HTML
Browser API
is an extension of the HTML
<iframe>
element that allows web apps to implement browsers or browser-like applications. It currently works in (privileged) chrome code on Firefox desktop (version 47 and above).
The Browser API consists of two major parts:
<iframe>
attributes: By adding a
mozbrowser
属性到
<iframe>
element we can make it appear like a top-level browser window to the embedded content. This means that
window.top
,
window.parent
,
window.frameElement
, etc. should
not
reflect the frame hierarchy.
HTMLIFrameElement
接口。
To support the requirement of a browser
<iframe>
,
HTMLIFrameElement
DOM interface has been extended with new methods that give the
<iframe>
some super powers.
The following navigation methods allow navigation through the browsing history of the
<iframe>
. They are necessary to be able to implement back, forward, stop, and reload buttons.
HTMLIFrameElement.reload()
<iframe>
element content.
HTMLIFrameElement.stop()
<iframe>
's content loading.
HTMLIFrameElement.getCanGoBack()
Indicates whether it's possible to navigate backwards.
HTMLIFrameElement.goBack()
<iframe>
for the previous location in its browsing history.
HTMLIFrameElement.getCanGoForward()
Indicates whether it's possible to navigate forward.
HTMLIFrameElement.goForward()
<iframe>
for the next location in its browsing history.
The next set of methods manage the resources used by a browser
<iframe>
. These are especially useful for implementing tabbed browser application.
HTMLIFrameElement.setVisible()
<iframe>
. This can influence resource allocation and some function usage such as
requestAnimationFrame
.
HTMLIFrameElement.getVisible()
<iframe>
.
HTMLIFrameElement.setActive()
<iframe>
as the active frame, which has an effect on how it is prioritized by the process manager.
HTMLIFrameElement.getActive()
<iframe>
is the currently active frame.
The following methods allow direct control of sound in the browser element.
HTMLIFrameElement.getVolume()
<iframe>
.
HTMLIFrameElement.setVolume()
<iframe>
.
HTMLIFrameElement.mute()
<iframe>
.
HTMLIFrameElement.unmute()
<iframe>
.
HTMLIFrameElement.getMuted()
<iframe>
is currently muted.
In order to manage the browser
<iframe>
's content, many new events were added (see below). The following methods are used to deal with those events:
<iframe>
gains support for the methods of the
EventTarget
interface
addEventListener()
,
removeEventListener()
,和
dispatchEvent()
.
HTMLIFrameElement.sendMouseEvent()
MouseEvent
到
<iframe>
's content.
Last, there are some utility methods, useful for apps that host a browser
<iframe>
.
HTMLIFrameElement.getStructuredData()
<iframe>
and returns it as JSON.
In Firefox 65, several of the Mozilla Browser API methods were removed in an effort to cut down on
DOMRequest
usage in the browser, and remove the parts of the Browser API that are no longer needed (it is used only by the Firefox DevTools at this point). See
bug 1503070
了解更多细节。
The methods removed in Firefox 65 are:
HTMLIFrameElement.addNextPaintListener()
MozAfterPaint
event in the browser
<iframe>
.
HTMLIFrameElement.clearMatch()
findAll()
or
findNext()
.
HTMLIFrameElement.download()
Downloads a specified URL, storing it at the specified filename/path.
HTMLIFrameElement.executeScript()
<iframe>
.
HTMLIFrameElement.findAll()
<iframe>
's content; if found, the first instance of the string relative to the caret position will be highlighted.
HTMLIFrameElement.findNext()
findAll()
search has been carried out.
HTMLIFrameElement.getContentDimensions()
Retrieves the X and Y dimensions of the content window.
HTMLIFrameElement.getManifest()
<iframe>
and returns it as JSON.
HTMLIFrameElement.getScreenshot()
<iframe>
's content. This is particularly useful to get thumbnails of tabs in a tabbed browser app.
HTMLIFrameElement.purgeHistory()
<iframe>
.
HTMLIFrameElement.sendTouchEvent()
TouchEvent
到
<iframe>
's content. Note that this method is available for touch enabled devices only.
HTMLIFrameElement.removeNextPaintListener()
addNextPaintListener()
.
HTMLIFrameElement.zoom()
<iframe>
's content. This is particularly useful for zooming in/out on non-touch-enabled devices.
In order to allow an application to manage the browser
<iframe>
, the application can listen for new events about what's happening within the browser
<iframe>
. The following new events can be listened for:
<iframe>
triggers a web activity, and that web activity's message is consumed by the receiving app.
<iframe>
content scrolls (the APCZ version.) See also
mozbrowserscroll
. Note that this is obsolete.
<iframe>
内容。
<iframe>
content changes.
window.close()
is called within a browser
<iframe>
.
<iframe>
tries to open a context menu. This allows handling of the
<menuitem>
element available within the browser
<iframe>
's content.
<iframe>
.
<iframe>
.
<iframe>
content (see
HTMLIFrameElement search methods
)。
<iframe>
paints content for the first time (this doesn't include the initial paint from
about:blank
)。
<link rel="icon">
or
<link rel="apple-touch-icon">
) is available in the browser
<iframe>
's content.
<iframe>
has finished loading all its assets.
<iframe>
starts to load a new page.
<iframe>
's location changes.
<iframe>
with an open web app embedded in it.
<meta>
elelment is added to, removed from or changed in the browser
<iframe>
's content.
window.open()
is called within a browser
<iframe>
.
<iframe>
as a result of the user issuing a command to open a link target in a new tab (for example
ctrl
/
cmd
+ click.)
<iframe>
's window size has changed.
<iframe>
content scrolls.
<iframe>
changes. This can occur on resize and when the page size changes (while loading for example.)
Sent when asynchronous scrolling (i.e. APCZ) starts or stops.
<iframe>
.
<iframe>
content changes. Note that this is obsolete, and newer implementations use
mozbrowsercaretstatechanged
代替。
alert()
,
confirm()
,或
prompt()
are called within a browser
<iframe>
.
<iframe>
.
Sent when an HTTP authentification is requested.
Sent when a link to a search engine is found.
<iframe>
changes, for example due to a call to
setVisible()
.
This API isn't part of any official specification.
HTMLIFrameElement.addNextPaintListener()
HTMLIFrameElement.clearMatch()
HTMLIFrameElement.download()
HTMLIFrameElement.executeScript()
HTMLIFrameElement.findAll()
HTMLIFrameElement.findNext()
HTMLIFrameElement.getActive()
HTMLIFrameElement.getCanGoBack()
HTMLIFrameElement.getCanGoForward()
HTMLIFrameElement.getContentDimensions()
HTMLIFrameElement.getMainfest()
HTMLIFrameElement.getMuted()
HTMLIFrameElement.getScreenshot()
HTMLIFrameElement.getStructuredData()
HTMLIFrameElement.goBack()
HTMLIFrameElement.goForward()
HTMLIFrameElement.getVisible()
HTMLIFrameElement.getVolume()
HTMLIFrameElement.mute()
HTMLIFrameElement.purgeHistory()
HTMLIFrameElement.reload()
HTMLIFrameElement.removeNextPaintListener()
HTMLIFrameElement.sendMouseEvent()
HTMLIFrameElement.sendTouchEvent()
HTMLIFrameElement.setActive()
HTMLIFrameElement.setInputMethodActive()
HTMLIFrameElement.setNFCFocus()
HTMLIFrameElement.setVisible()
HTMLIFrameElement.setVolume()
HTMLIFrameElement.stop()
HTMLIFrameElement.unmute()
HTMLIFrameElement.zoom()
mozbrowseractivitydone
mozbrowserasyncscroll
mozbrowseraudioplaybackchange
mozbrowsercaretstatechanged
mozbrowserclose
mozbrowsercontextmenu
mozbrowserdocumentfirstpaint
mozbrowsererror
mozbrowserfindchange
mozbrowserfirstpaint
mozbrowsericonchange
mozbrowserloadend
mozbrowserloadstart
mozbrowserlocationchange
mozbrowsermanifestchange
mozbrowsermetachange
mozbrowseropensearch
mozbrowseropentab
mozbrowseropenwindow
mozbrowserresize
mozbrowserscroll
mozbrowserscrollareachanged
mozbrowserscrollviewchange
mozbrowsersecuritychange
mozbrowserselectionstatechanged
mozbrowsershowmodalprompt
mozbrowsertitlechange
mozbrowserusernameandpasswordrequired
mozbrowservisibilitychange