MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey-2018-1

この翻訳は不完全です。英語から この記事を翻訳 してください。

ナビゲーションのいろいろな段階でイベントリスナーを追加します。ナビゲーションにはある URL から他に移動するブラウザーフレームにより成り立っていて、それは(いつもではなく)通常はリンクのクリックやロケーションバーへの URL 入力といったユーザー操作の応答として発生します。

webRequest API と比較して: ナビゲーションは通常、ブラウザーにウェブリクエストを発生させますが、webRequest API は HTTP 層からの低レベルな観点に関心を持っていおり、一方で webNavigation API はブラウザー UI 自身に対して、より関心を持っています。

Each event corresponds to a particular stage in the navigation. The sequence of events is like this:

Each navigation is a URL transition in a particular browser frame. The browser frame is identified by a tab ID and a frame ID. The frame may be the top-level browsing context in the tab, or may be a nested browsing context implemented as an iframe.

Each event's addListener() call accepts an optional filter parameter. The filter will specify one or more URL patterns, and the event will then only be fired for navigations in which the target URL matches one of the patterns.

The onCommitted event listener is passed two additional properties: a TransitionType indicating the cause of the navigation (for example, because the user clicked a link, or because the user selected a bookmark), and a TransitionQualifier providing further information about the navigation.

To use this API you need to have the "webNavigation" permission.

webNavigation.TransitionType
Cause of the navigation: for example, the user clicked a link, or typed an address, or clicked a bookmark.
webNavigation.TransitionQualifier
Extra information about a transition.

関数

webNavigation.getFrame()
Retrieves information about a particular frame. A frame may be the top-level frame in a tab or a nested iframe, and is uniquely identified by a tab ID and a frame ID.
webNavigation.getAllFrames()

Given a tab ID, retrieves information about all the frames it contains.

イベント

webNavigation.onBeforeNavigate

Fired when the browser is about to start a navigation event.

webNavigation.onCommitted
Fired when a navigation is committed. At least part of the new document has been received from the server and the browser has decided to switch to the new document.
webNavigation.onDOMContentLoaded
Fired when the DOMContentLoaded event is fired in the page.
webNavigation.onCompleted
Fired when a document, including the resources it refers to, is completely loaded and initialized. This is equivalent to the DOM load event.
webNavigation.onErrorOccurred
Fired when an error occurs and the navigation is aborted. This can happen if either a network error occurred, or the user aborted the navigation.
webNavigation.onCreatedNavigationTarget
Fired when a new window, or a new tab in an existing window, is created to host a navigation: for example, if the user opens a link in a new tab.
webNavigation.onReferenceFragmentUpdated
Fired if the fragment identifier for a page is changed.
webNavigation.onTabReplaced

Fired when the contents of the tab is replaced by a different (usually previously pre-rendered) tab.

webNavigation.onHistoryStateUpdated
Fired when the page used the history API to update the URL displayed in the browser's location bar.

ブラウザ実装状況

ChromeEdgeFirefoxFirefox for AndroidOpera
TransitionQualifier 有り 無し48 *48 *17
TransitionType 有り 無し48 *48 *17
getAllFrames 有り 有り474817
getFrame 有り 有り474817
onBeforeNavigate 有り * 有り *45 *48 *17 *
onCommitted 有り * 有り *45 *48 *17 *
onCompleted 有り * 有り *45 *48 *17 *
onCreatedNavigationTarget 有り * 有り54 *54 *17 *
onDOMContentLoaded 有り * 有り *45 *48 *17 *
onErrorOccurred 有り * 有り *45 *48 *17 *
onHistoryStateUpdated 有り 有り *47 *4817
onReferenceFragmentUpdated 有り * 有り *45 *48 *17 *
onTabReplaced 有り 有り45 *48 *17

Example extensions

Acknowledgements

This API is based on Chromium's chrome.webNavigation API. This documentation is derived from web_navigation.json in the Chromium code.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

ドキュメントのタグと貢献者

 このページの貢献者: Uemmra3
 最終更新者: Uemmra3,