1. 7.2 ナビゲーションおよびセッション履歴に関連するAPI
      1. 7.2.1 Windowオブジェクト
        1. 7.2.1.1 ウィンドウの開閉
        2. 7.2.1.2 Windowオブジェクトのインデックス付きアクセス
        3. 7.2.1.3 Windowオブジェクトの名前付きアクセス
        4. 7.2.1.4 関連ウィンドウへのアクセス
        5. 7.2.1.5 歴史的なブラウザーインターフェイス要素API
      2. 7.2.2 WindowProxy外来オブジェクト
      3. 7.2.3 Locationインターフェイス
      4. 7.2.4 Historyインターフェイス
      5. 7.2.5 ナビゲーションAPI
        1. 7.2.5.1 導入
        2. 7.2.5.2 Navigationインターフェイス
        3. 7.2.5.3 コアインフラ
        4. 7.2.5.4 NavigationHistoryEntryインターフェイス
        5. 7.2.5.5 履歴エントリーリスト
        6. 7.2.5.6 Initiating navigations
        7. 7.2.5.7 進行中のナビゲーショントラッキング
        8. 7.2.5.8 NavigationActivationインターフェイス
        9. 7.2.5.9 navigateイベント
          1. 7.2.5.9.1 The NavigateEvent interface
          2. 7.2.5.9.2 The NavigationDestination interface
      6. 7.2.6 イベントインターフェイス
        1. 7.2.6.1 NavigationCurrentEntryChangeEventインターフェイス
        2. 7.2.6.2 PopStateEventインターフェイス
        3. 7.2.6.3 HashChangeEventインターフェイス
        4. 7.2.6.4 PageSwapEventインターフェイス
        5. 7.2.6.5 PageRevealEventインターフェイス
        6. 7.2.6.6 PageTransitionEventインターフェイス
        7. 7.2.6.7 BeforeUnloadEventインターフェイス
      7. 7.2.7 The NotRestoredReasons interface

7.2.1 Windowオブジェクト

Window

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera3+Edge79+
Edge (Legacy)12+Internet Explorer4+
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android10.1+
window.window
window.frames
window.self

これらの属性はすべてwindowを返す。

window.document

windowと関連するDocumentを返す。

document.defaultView

documentに関連付けられたWindowがある場合はそれを返し、そうでなければnullを返す。

7.2.1.1 ウィンドウの開閉
window = window.open([ url [, target [, features ] ] ])

url(デフォルトで"about:blank")を表示するためのウィンドウを開き、それを返す。target(デフォルトで"_blank")は、新しいウィンドウの名前を示す。すでにその名前をもつウィンドウが存在する場合、それが再利用される。features引数はコンマ区切りトークンの集合を含むことができる:

"noopener"
"noreferrer"

これらは、ハイパーリンク上のnoopenerおよびnoreferrerリンクタイプと同等に動作する。

"popup"

ユーザーエージェントに、新しいウィンドウに最小限のウェブブラウザーユーザーインターフェイスを提供するように促す。 (すべてのBarPropオブジェクトにもvisibleゲッターに影響を与える。)

globalThis.open("https://email.example/message/CAOOOkFcWW97r8yg=SsWg7GgCmp4suVX9o85y8BvNRqMjuc5PXg", undefined, "noopener,popup");
window.name [ = value ]

ウィンドウの名前を返す。

名前を変更する設定が可能である。

window.close()

ウィンドウを閉じる。

window.closed

ウィンドウが閉じられている場合はtrueを返し、そうでなければfalseを返す。

window.stop()

ドキュメントの読み込みを中止する。

7.2.1.2 Windowオブジェクトのインデックス付きアクセス
window.length

文書ツリーの子ナビゲート可能の数を返す。

window[index]

指定された文書ツリーの子ナビゲート可能に対応するWindowProxyを返す。

7.2.1.3 Windowオブジェクトの名前付きアクセス
window[name]

指示された要素または要素のコレクションを返す。

一般的な規則として、これに依存することはもろいコードを導く。たとえば、新しい機能がウェブプラットフォームに加えられるように、いずれかのIDがこのAPIのマッピングで終わることは時間をかけて変化できる。この代わりに、document.getElementById()またはdocument.querySelector()を使用する。

window.top

トップレベルトラバーサルWindowProxyを返す。

window.opener [ = value ]

オープナーブラウジングコンテキストに対するWindowProxyを返す。

存在しないまたはnullが設定されている場合、nullを返す。

nullに設定可能である。

window.parent

親ナビゲート可能に対するWindowProxyを返す。

window.frameElement

ナビゲート可能コンテナー要素を返す。

存在しない場合、生成元をまたいだ状況でnullを返す。

7.2.1.5 歴史的なブラウザーインターフェイス要素API

歴史的な理由から、Windowインターフェイスには、特定のウェブブラウザーインターフェイス要素の可視性を表すいくつかのプロパティがあった。

プライバシーと相互運用性の理由から、ウィンドウがポップアップウィンドウを表しているかどうかに関係なく、これらのプロパティはすべて同じ値を返すようになった。

window.locationbar.visible

BarProp/visible

Support in all current engines.

Firefox1+Safari3+Chrome1+
Opera?Edge79+
Edge (Legacy)12+Internet ExplorerNo
Firefox Android?Safari iOS1+Chrome Android?WebView Android37+Samsung Internet?Opera Android?
window.menubar.visible
window.personalbar.visible
window.scrollbars.visible
window.statusbar.visible
window.toolbar.visible

Windowがポップアップでない場合はtrueを返す。そうでなければfalseを返す。

7.2.2 WindowProxy外来オブジェクト

WindowProxyは、Windowの通常のオブジェクトをラップする外来オブジェクトであり、ほとんどの操作をラップされたオブジェクトに間接的に転送する。各ブラウジングコンテキストは、関連するWindowProxyオブジェクトを持つ。ブラウジングコンテキストナビゲートされるとき、ブラウジングコンテキストの関連付けられたWindowProxyオブジェクトによってラップされたWindowオブジェクトが変更される。

7.2.3 Locationインターフェイス

Document/location

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera3+Edge79+
Edge (Legacy)12+Internet Explorer4+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android10.1+

Location

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera3+Edge79+
Edge (Legacy)12+Internet Explorer3+
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet?Opera Android10.1+

Window/location

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera3+Edge79+
Edge (Legacy)12+Internet Explorer4+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android10.1+

Windowオブジェクトは、Locationオブジェクトの一意なインスタンスに関連付けられており、Windowオブジェクトの作成時に割り当てられる。

document.location [ = value ]
window.location [ = value ]

現在のページの位置とLocationオブジェクトを返す。

別のページにナビゲートするために、設定可能である。

Locationオブジェクトは、関連付けられたDocumentURLの表現と、関連付けられたナビゲート可能ナビゲートおよびリロードするためのメソッドを提供する。

location.toString()
location.href

LocationオブジェクトのURLを返す。

与えられたURLにナビゲートするように、設定可能である。

location.origin

Locationオブジェクトの生成元を返す。

location.protocol

Locationオブジェクトのスキームを返す。

変更されたスキームと同じURLにナビゲートするように、設定可能である。

location.host

LocationオブジェクトのURLのホストとポートを返す(スキームのデフォルトポートと異なる場合)。

変更されたホストおよびポートと同じURLにナビゲートするように、設定可能である。

location.hostname

Locationオブジェクトのホストを返す。

変更されたホストと同じURLにナビゲートするように、設定可能である。

location.port

Locationオブジェクトのポートを返す。

変更されたポートと同じURLにナビゲートするように、設定可能である。

location.pathname

Locationオブジェクトのパスを返す。

変更されたパスと同じURLにナビゲートするように、設定可能である。

location.search

LocationオブジェクトのURLのクエリーを返す(空でない場合は先頭の"?"を含む)。

(先頭の"?"を無視して)変更されたクエリーと同じURLにナビゲートするように、設定可能である。

location.hash

LocationオブジェクトのURLのフラグメントを返す(空でない場合は先頭の"#"を含む)。

(先頭の"#"を無視して)変更されたフラグメントと同じURLにナビゲートするように、設定可能である。

location.assign(url)

与えられたURLにナビゲートする。

location.replace(url)

セッション履歴から現在のページを削除し、与えられたURLにナビゲートする。

location.reload()

現在のページをリロードする。

location.ancestorOrigins

祖先ナビゲート可能アクティブな文書の生成元を列挙する DOMStringListオブジェクトを返す。

7.2.4 Historyインターフェイス

History

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera3+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android10.1+

Window/history

Support in all current engines.

Firefox1+Safari1+Chrome1+
Opera3+Edge79+
Edge (Legacy)12+Internet Explorer4+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android10.1+
history.length

現在のトラバース可能なナビゲート可能の全体のセッション履歴エントリーの数を返す。

history.scrollRestoration

アクティブなセッション履歴エントリースクロール復元モードを返す。

history.scrollRestoration = value

アクティブなセッション履歴エントリースクロール復元モードvalueに設定する。

history.state

アクティブなセッション履歴エントリークラシック履歴API状態を、JavaScript値にデシリアライズして返す。

history.go()

現在のページをリロードする。

history.go(delta)

現在のトラバース可能なナビゲート可能の全体のセッション履歴エントリーリストで、指定された数のステップを前後に移動する。

ゼロ差分は、現在のページをリロードする。

差分が範囲外の場合、何もしない。

history.back()

現在のトラバース可能なナビゲート可能の全体のセッション履歴エントリーリストで1ステップ戻る。

前のページが存在しない場合、何もしない。

history.forward()

現在のトラバース可能なナビゲート可能の全体のセッション履歴エントリーリストで1ステップ進める。

次のページが存在しない場合、何もしない。

history.pushState(data, "")

クラシック履歴API状態データのシリアル化に設定して、セッション履歴に新しいエントリーを追加する。アクティブな履歴エントリーURLがコピーされ、新しいエントリーのURLに使用される。

(2番目のパラメーターは歴史的な理由で存在し、省略することはできない。空の文字列を渡すことは慣例的なものである。)

history.pushState(data, "", url)

クラシック履歴API状態データのシリアル化に設定し、 URLurlに設定して、セッション履歴に新しいエントリーを追加する。

現在のDocumentがURLをurl書き換えることができない場合、"SecurityError" DOMExceptionが投げられる。

(2番目のパラメーターは歴史的な理由で存在し、省略することはできない。空の文字列を渡すことは慣例的なものである。)

history.replaceState(data, "")

アクティブセッション履歴エントリークラシック履歴API状態を、 データの構造化クローンに更新する。

(2番目のパラメーターは歴史的な理由で存在し、省略することはできない。空の文字列を渡すことは慣例的なものである。)

history.replaceState(data, "", url)

アクティブなセッション履歴エントリークラシック履歴API状態データの構造化クローンに更新し、そのURLurlに更新する。

現在のDocumentがURLをurl書き換えることができない場合、"SecurityError" DOMExceptionが投げられる。

(2番目のパラメーターは歴史的な理由で存在し、省略することはできない。空の文字列を渡すことは慣例的なものである。)

document's URLtargetURLcan have its URL rewritten
https://example.com/homehttps://example.com/home#about
https://example.com/homehttps://example.com/home?page=shop
https://example.com/homehttps://example.com/shop
https://example.com/homehttps://user:pass@example.com/home
https://example.com/homehttp://example.com/home
file:///path/to/xfile:///path/to/x#hash
file:///path/to/xfile:///path/to/x?search
file:///path/to/xfile:///path/to/y
about:blankabout:blank#hash
about:blankabout:blank?search
about:blankabout:srcdoc
data:text/html,foodata:text/html,foo#hash
data:text/html,foodata:text/html,foo?search
data:text/html,foodata:text/html,bar
data:text/html,foodata:bar
blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43#hash
blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43?search
blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43blob:https://example.com/anything
blob:https://example.com/77becafe-657b-4fdc-8bd3-e83aaa5e8f43blob:path

DocumentURLのみが重要であり、その生成元は重要ではないことに注意する。継承された生成元をもつabout:blank Document、サンフォボックスiframe、またはdocument.domainセッターが使用されている場合のように、これらが一致しないことがある。

ユーザーはいくつかの座標に常にあり、ユーザーが後で再開するための特定の座標に対応するページをブックマークできるような、ユーザーがラインに沿って移動できるゲームを考える。

そのようなゲームでx=5位置を実装する静的ページは次のようになる:

<!DOCTYPE HTML>
<!-- this is https://example.com/line?x=5 -->
<html lang="en">
<title>Line Game - 5</title>
<p>You are at coordinate 5 on the line.</p>
<p>
 <a href="?x=6">Advance to 6</a> or
 <a href="?x=4">retreat to 4</a>?
</p>

このようなシステムの問題点は、毎回ユーザーがクリックするとページ全体をリロードする必要があることにある。ここで、代わりにスクリプトを使用して、リロードを行うための別の方法:

<!DOCTYPE HTML>
<!-- this starts off as https://example.com/line?x=5 -->
<html lang="en">
<title>Line Game - 5</title>
<p>You are at coordinate <span id="coord">5</span> on the line.</p>
<p>
 <a href="?x=6" onclick="go(1); return false;">Advance to 6</a> or
 <a href="?x=4" onclick="go(-1); return false;">retreat to 4</a>?
</p>
<script>
 var currentPage = 5; // prefilled by server
 function go(d) {
   setupPage(currentPage + d);
   history.pushState(currentPage, "", '?x=' + currentPage);
 }
 onpopstate = function(event) {
   setupPage(event.state);
 }
 function setupPage(page) {
   currentPage = page;
   document.title = 'Line Game - ' + currentPage;
   document.getElementById('coord').textContent = currentPage;
   document.links[0].href = '?x=' + (currentPage+1);
   document.links[0].textContent = 'Advance to ' + (currentPage+1);
   document.links[1].href = '?x=' + (currentPage-1);
   document.links[1].textContent = 'retreat to ' + (currentPage-1);
 }
</script>

スクリプトをもたないシステムにおいて、前の例と同じように動作する。しかし、同じ体験に対するネットワークアクセスが存在しないので、スクリプトをサポートするユーザーは現在はるかに速く移動できる。さらに、経験に反して、ユーザーは単にナイーブなスクリプトベースのアプローチ、ブックマーク、およびセッション履歴の移動が依然として動作する必要がある。

上記の例において、pushState()メソッドへのdata引数は、サーバーに送信されるものと同じ情報であるが、スクリプトはURLにユーザーが移動するたびに解析する必要はないので、より便利な形式となる。

ほとんどのアプリケーションは、すべての履歴エントリーに同じスクロール復元モード値を使用したいと考えている。これを実現するために、できるだけ早くscrollRestoration属性を設定して(たとえば、文書のhead要素の最初のscript要素で)、履歴セッションに追加されたエントリーが確実に希望のスクロール復元モードになるようにする。

<head>
  <script>
       if ('scrollRestoration' in history)
            history.scrollRestoration = 'manual';
  </script>
</head>
   

グローバルnavigationプロパティによって提供されるナビゲーションAPIは、ナビゲーションおよび履歴エントリーを管理するための最新のウェブアプリケーションに焦点を当てた方法を提供する。これは、従来のlocationおよびhistoryの後継である。

APIが提供する機能の1つは、セッション履歴エントリーの検査である。たとえば、次の例では、エントリーのURLが順序付きリストに表示される:

const ol = document.createElement("ol");
ol.start = 0; // so that the list items' ordinal values match up with the entry indices

for (const entry of navigation.entries()) {
  const li = document.createElement("li");

  if (entry.index < navigation.currentEntry.index) {
    li.className = "backward";
  } else if (entry.index > navigation.currentEntry.index) {
    li.className = "forward";
  } else {
    li.className = "current";
  }

  li.textContent = entry.url;
  ol.append(li);
}

navigation.entries()配列にはNavigationHistoryEntryインスタンスが含まれており、これには、ここに示すurlおよびindexプロパティに加えて、その他の便利なプロパティがある。配列には、現在のナビゲート可能を表すNavigationHistoryEntryオブジェクトのみが含まれるため、その内容は、iframeなどのナビゲート可能なコンテナー内のナビゲーションまたは、ナビゲーションAPI自身がiframe内で使用されている場合の親ナビゲート可能のナビゲーションの影響を受けないことに注意する。さらに、同一生成元セッション履歴エントリーを表す NavigationHistoryEntryオブジェクトのみが含まれる。つまり、ユーザーが現在の生成元の前後に他の生成元を訪問した場合、対応するNavigationHistoryEntryは存在しない。


ナビゲーションAPIを使用して、履歴をナビゲート、リロード、またはトラバースすることもできる:

<button onclick="navigation.reload()">Reload</button>

<input type="url" id="navigationURL">
<button onclick="navigation.navigate(navigationURL.value)">Navigate</button>

<button id="backButton" onclick="navigation.back()">Back</button>
<button id="forwardButton" onclick="navigation.forward()">Forward</button>

<select id="traversalDestinations"></select>
<button id="goButton" onclick="navigation.traverseTo(traversalDestinations.value)">Traverse To</button>

<script>
backButton.disabled = !navigation.canGoBack;
forwardButton.disabled = !navigation.canGoForward;

for (const entry of navigation.entries()) {
  traversalDestinations.append(new Option(entry.url, entry.key));
}
</script>

ここでも、トラバーサルは同一生成元の宛先に制限されることに注意する。つまり、たとえば、前のセッション履歴エントリーが別の生成元からのページに対するものである場合、navigation.canGoBackはfalseになる。


ナビゲーションAPIの最も強力な部分は、navigateイベントである。このイベントは、現在のナビゲート可能でほとんどすべてのナビゲーションまたはトラバースが発生したときに発火する。

navigation.onnavigate = event => {
  console.log(event.navigationType); // "push", "replace", "reload", or "traverse"
  console.log(event.destination.url);
  console.log(event.userInitiated);
  // ... and other useful properties
};

(ナビゲーションの移動先が新しい文書である場合、ロケーションバーによって開始されたナビゲーションまたは他のウィンドウから開始されたナビゲーションに対してはイベントは発火しない。)

ほとんどの場合、イベントの cancelableプロパティはtrueになる。つまり、このイベントはpreventDefault()を使用してキャンセルできる:

navigation.onnavigate = event => {
  if (event.cancelable && isDisallowedURL(event.destination.url)) {
    alert(`Please don't go to ${event.destination.url}!`);
    event.preventDefault();
  }
};

一部の"traverse"ナビゲーションでは、cancelableプロパティがfalseになる。これには、子ナビゲーション可能内で行われるナビゲーション、新しい生成元に交差するナビゲーション、またはpreventDefault()の前回の呼び出しでトラバースできなかった直後にユーザーが再度トラバースしようとした場合などがある。

NavigateEventintercept()メソッドを使用すると、ナビゲーションを横取りして、同じ文書のナビゲーションに変換できる:

navigation.addEventListener("navigate", e => {
  // Some navigations, e.g. cross-origin navigations, we cannot intercept.
  // Let the browser handle those normally.
  if (!e.canIntercept) {
    return;
  }

  // Similarly, don't intercept fragment navigations or downloads.
  if (e.hashChange || e.downloadRequest !== null) {
    return;
  }

  const url = new URL(event.destination.url);

  if (url.pathname.startsWith("/articles/")) {
    e.intercept({
      async handler() {
        // The URL has already changed, so show a placeholder while
        // fetching the new content, such as a spinner or loading page.
        renderArticlePagePlaceholder();

        // Fetch the new content and display when ready.
        const articleContent = await getArticleContent(url.pathname, { signal: e.signal });
        renderArticlePage(articleContent);
      }
    });
  }
});

handlerは、ナビゲーションの非同期進行、および成功または失敗を表すプロミスを返すことができることに注意する。プロミスがまだ保留中である間、ブラウザーUIは、ナビゲーションを進行中として扱うことができる(たとえば、ローディングスピナーを提示することによって)。ナビゲーションAPIの他の部分も、navigation.navigate()の返り値など、これらのプロミスに敏感である:

const { committed, finished } = await navigation.navigate("/articles/the-navigation-api-is-cool");

// The committed promise will fulfill once the URL has changed, which happens
// immediately (as long as the NavigateEvent wasn't canceled).
await committed;

// The finished promise will fulfill once the Promise returned by handler() has
// fulfilled, which happens once the article is downloaded and rendered. (Or,
// it will reject, if handler() fails along the way).
await finished;

下記は、Navigationインターフェイスを実装するすべてのオブジェクトによって、イベントハンドラーIDL属性として、サポートされるイベントハンドラー(および対応するイベントハンドラーイベント型)である:

イベントハンドラーイベントハンドラーイベント型
onnavigatenavigate
onnavigatesuccessnavigatesuccess
onnavigateerrornavigateerror
oncurrententrychangecurrententrychange

ナビゲーションAPI全体で使用されるキータイプは、NavigationType列挙である:

これは、主要なウェブ開発者が目に見える"navigation"のタイプをキャプチャしたものであり、(他の場所で指摘されているように)この標準の特異なナビゲートアルゴリズムに正確に対応していない。それぞれの値の意味は次のとおりである:

"push"
history handling behaviorが"push"で終わるナビゲート、またはhistory.pushState()の呼び出しに対応する。
"replace"
history handling behaviorが"replace"で終わるナビゲート、またはhistory.replaceState()の呼び出しに対応する。
"reload"
reloadの呼び出しに対応する。
"traverse"
履歴をデルタ単位でトラバースの呼び出しに対応する。
7.2.5.4 NavigationHistoryEntryインターフェイス
entry.url

このナビゲーション履歴エントリーのURL。

エントリーが現在のものとは異なるDocumentに対応している場合(つまり、 sameDocumentがfalseである場合)、かつDocumentが"no-referrer"または"origin"のリファラーポリシーで取得された場合、nullを返すことができる。これは、問題のDocumentが他の同じ生成元のページからもURLを隠していることを示しているためである。

entry.key

ナビゲーション履歴リスト内のこのナビゲーション履歴エントリーの位置を表す、ユーザーエージェントが生成したランダムなUUID文字列。この値は、"replace"ナビゲーションのためにこの値を置き換える他の NavigationHistoryEntryインスタンスによって再利用され、再読み込みおよびセッションの復元後も存続する。

これは、navigation.traverseTo(key)を使用して、ナビゲーション履歴リストのこのエントリーに戻るのに役立つ。

entry.id

この特定のナビゲーション履歴エントリーを表す、ユーザーエージェントによって生成されたランダムなUUID文字列。この値は、他のNavigationHistoryEntryインスタンスによって再利用されない。この値は、リロードおよびセッションのリストア後も保持される。

これは、他のストレージAPIを使用してこのナビゲーション履歴エントリーにデータを関連付ける場合に役立つ。

entry.index

navigation.entries()内のこのNavigationHistoryEntryのインデックス。または、エントリーがナビゲーション履歴エントリーリストにない場合は-1。

entry.sameDocument

このナビゲーション履歴エントリーが現在のDocumentと同じかどうかを示す。たとえば、エントリーがフラグメントナビゲーションまたは単一ページのアプリナビゲーションを表す場合、これはtrueになる。

entry.getState()

navigation.navigate()またはnavigation.updateCurrentEntry()を用いてエントリーに追加された、このエントリーに格納されている状態のデシリアライズを返す。この状態は、リロードおよびセッションのリストア後も保持される。

一般に、状態値がプリミティブentry.getState() !== entry.getState()でない限り、毎回新しいデシリアライズが返されることに注意する。

この状態は、従来の履歴API history.stateとは関係ない。

下記は、NavigationHistoryEntryインターフェイスを実装するすべてのオブジェクトによって、イベントハンドラーIDL属性として、サポートされるイベントハンドラー(および対応するイベントハンドラーイベント型)である:

イベントハンドラーイベントハンドラーイベント型
ondisposedispose
7.2.5.5 履歴エントリーリスト
entries = navigation.entries()

現在のナビゲーション履歴エントリーリストを表すNavigationHistoryEntryインスタンスの配列を返す。これはつまり、現在のセッション履歴エントリー同一生成元で隣接する、このナビゲーション可能のすべてのセッション履歴エントリー</23>である。

navigation.currentEntry

現在のセッション履歴エントリーに対応するNavigationHistoryEntryを返す。

navigation.updateCurrentEntry({ state })

navigation.reload()のようなナビゲーションを実行せずに、現在のセッション履歴エントリーナビゲーションAPI状態を更新する。

このメソッドは、すでに発生しており、ナビゲーションAPI状態に反映する必要があるページの更新をキャプチャするのに最適である。状態の更新がページ更新を駆動することを意図している場合、代わりにnavigation.navigate()または navigation.reload()を使用する。これにより、 navigateイベントがトリガーされる。

navigation.canGoBack

現在の現在のセッション履歴エントリーつまり、(currentEntry)がナビゲーション履歴エントリーリストの最初のエントリー(つまり、entries())でない場合、trueを返す。これは、このナビゲート可能に対して以前のセッション履歴エントリーがあり、その文書状態生成元が現在のDocument生成元同一生成元であることを意味する。

navigation.canGoForward

現在の現在のセッション履歴エントリーつまり、(currentEntry)がナビゲーション履歴エントリーリストの最後のエントリー(つまり、entries())でない場合、trueを返す。これは、このナビゲート可能に対して次のセッション履歴エントリーがあり、その文書状態生成元が現在のDocument生成元同一生成元であることを意味する。

{ committed, finished } = navigation.navigate(url)
{ committed, finished } = navigation.navigate(url, options)

Navigates the current page to the given url. options can contain the following values:

By default this will perform a full navigation (i.e., a cross-document navigation, unless the given URL differs only in a fragment from the current one). The navigateEvent.intercept() method can be used to convert it into a same-document navigation.

The returned promises will behave as follows:

In all cases, when the returned promises fulfill, it will be with the NavigationHistoryEntry that was navigated to.

{ committed, finished } = navigation.reload(options)

Reloads the current page. options can contain info and state, which behave as described above.

The default behavior of performing a from-network-or-cache reload of the current page can be overriden by the using the navigateEvent.intercept() method. Doing so will mean this call only updates state or passes along the appropriate info, plus performing whater actions the navigate event handlers see fit to carry out.

The returned promises will behave as follows:

{ committed, finished } = navigation.traverseTo(key)
{ committed, finished } = navigation.traverseTo(key, { info })

Traverses to the closest session history entry that matches the NavigationHistoryEntry with the given key. info can be set to any value; it will populate the info property of the corresponding NavigateEvent.

If a traversal to that session history entry is already in progress, then this will return the promises for that original traversal, and info will be ignored.

The returned promises will behave as follows:

{ committed, finished } = navigation.back(key)
{ committed, finished } = navigation.back(key, { info })

Traverses to the closest previous session history entry which results in this navigable traversing, i.e., which corresponds to a different NavigationHistoryEntry and thus will cause navigation.currentEntry to change. info can be set to any value; it will populate the info property of the corresponding NavigateEvent.

If a traversal to that session history entry is already in progress, then this will return the promises for that original traversal, and info will be ignored.

The returned promises behave equivalently to those returned by traverseTo().

{ committed, finished } = navigation.forward(key)
{ committed, finished } = navigation.forward(key, { info })

Traverses to the closest forward session history entry which results in this navigable traversing, i.e., which corresponds to a different NavigationHistoryEntry and thus will cause navigation.currentEntry to change. info can be set to any value; it will populate the info property of the corresponding NavigateEvent.

If a traversal to that session history entry is already in progress, then this will return the promises for that original traversal, and info will be ignored.

The returned promises behave equivalently to those returned by traverseTo().

7.2.5.7 進行中のナビゲーショントラッキング
navigation.transition

存在する場合、navigatesuccessまたはnavigateerrorステージに到達していない進行中のナビゲーションを表すNavigationTransition。そのような移行が進行中でない場合、nullになる。

navigation.currentEntry(および location.hrefなどの他のプロパティ)はナビゲーションの直後に更新されるため、このnavigation.transitionプロパティは、navigateEvent.intercept()に渡されたハンドラーに従って、そのようなナビゲーションがまだ完全に確定していないときを判断するのに役立つ。

navigation.transition.navigationType

"push"、"replace"、"reload"、または "traverse"のいずれかで、このトランジションのナビゲーションの種類を示す。

navigation.transition.from

遷移元のNavigationHistoryEntry。これはnavigation.currentEntryと比較するのに役立つ。

navigation.transition.finished

navigatesuccessが発火すると同時に実行されるプロミス、または navigateerrorイベントが発火すると同時に拒否されるプロミス。

navigation.activation

このDocumentを"activated"にしたナビゲーションである、最新の文書間ナビゲーションに関する情報を含むNavigationActivation

navigation.currentEntryDocumentURLは同じ文書のナビゲーションにより定期的に更新できるが、navigation.activationは一定に保たれ、Documentreactivated履歴から更新された場合にのみ、そのプロパティは更新される。

navigation.activation.entry

Documentがアクティブになった時点のnavigation.currentEntryプロパティの値と同じNavigationHistoryEntry

navigation.activation.from

現在のDocumentの直前にアクティブであったDocumentを表す NavigationHistoryEntry。前のDocumentがこの文書と同一生成元ではなかった場合、またはinitial about:blank Documentであった場合、値はnullになる。

fromまたはentry NavigationHistoryEntryオブジェクトは、履歴に保持されない可能性があるため、traverseTo()メソッドの実行可能なターゲットにならない場合がある。たとえば、Documentlocation.replace()を使用してアクティブにすることができ、その初期エントリーはhistory.replaceState()で置き換えることができる。しかし、これらのエントリーの<g13>urlプロパティおよびgetState()メソッドには引き続きアクセス可能である。

navigation.activation.navigationType

One of "push", "replace", "reload", or "traverse", indicating what type of navigation activated this Document.

Each Navigation has an associated activation, which is null or a NavigationActivation object, initially null.

Each NavigationActivation has:

The activation getter steps are to return this's activation.

The from getter steps are to return this's old entry.

The entry getter steps are to return this's new entry.

The navigationType getter steps are to return this's navigation type.

7.2.5.9 navigateイベント

ナビゲーションAPIの主な機能は、navigateイベントである。このイベントはすべてのナビゲーション(広義の意味で)で発火し、ウェブ開発者はそのような発信ナビゲーションを監視できる。多くの場合、イベントはcancelableであり、これはナビゲーションが発生しないようにすることができる。また、NavigateEventクラスのintercept()メソッドを使用して、ナビゲーションをインターセプトし、同じ文書のナビゲーションに置き換えることもできる。

7.2.5.9.1 The NavigateEvent interface
event.navigationType

One of "push", "replace", "reload", or "traverse", indicating what type of navigation this is.

event.destination

A NavigationDestination representing the destination of the navigation.

event.canIntercept

True if intercept() can be called to intercept this navigation and convert it into a same-document navigation, replacing its usual behavior; false otherwise.

Generally speaking, this will be true whenever the current Document can have its URL rewritten to the destination URL, except for in the case of cross-document "traverse" navigations, where it will always be false.

event.userInitiated

True if this navigation was due to a user clicking on an a element, submitting a form element, or using the browser UI to navigate; false otherwise.

event.hashChange

True for a fragment navigation; false otherwise.

event.signal

An AbortSignal which will become aborted if the navigation gets canceled, e.g., by the user pressing their browser's "Stop" button, or by another navigation interrupting this one.

The expected pattern is for developers to pass this along to any async operations, such as fetch(), which they perform as part of handling this navigation.

event.formData

The FormData representing the submitted form entries for this navigation, if this navigation is a "push" or "replace" navigation representing a POST form submission; null otherwise.

(Notably, this will be null even for "reload" or "traverse" navigations that are revisiting a session history entry that was originally created from a form submission.)

event.downloadRequest

Represents whether or not this navigation was requested to be a download, by using an a or area element's download attribute:

Note that a download being requested does not always mean that a download will happen: for example, a download might be blocked by browser security policies, or end up being treated as a "push" navigation for unspecified reasons.

Similarly, a navigation might end up being a download even if it was not requested to be one, due to the destination server responding with a `Content-Disposition: attachment` header.

Finally, note that the navigate event will not fire at all for downloads initiated using browser UI affordances, e.g., those created by right-clicking and choosing to save the target of a link.

event.info

An arbitrary JavaScript value passed via one of the navigation API methods which initiated this navigation, or undefined if the navigation was initiated by the user or by a different API.

event.hasUAVisualTransition

ユーザーエージェントが、このイベントをディスパッチする前に、このナビゲーションのビジュアルトランジションを実行した場合、trueを返す。trueの場合、著者がDOMをナビゲーション後の状態に同期的に更新するならば、最高のユーザーエクスペリエンスが得られる。

event.sourceElement

Returns the Element responsible for this navigation. This can be an aor area element, a submit button, or a submitted form element.

event.intercept({ handler, focusReset, scroll })

Intercepts this navigation, preventing its normal handling and instead converting it into a same-document navigation of the same type to the destination URL.

The handler option can be a function that returns a promise. The handler function will run after the navigate event has finished firing, and the navigation.currentEntry property has been synchronously updated. This returned promise is used to signal the duration, and success or failure, of the navigation. After it settles, the browser signals to the user (e.g., via a loading spinner UI, or assistive technology) that the navigation is finished. Additionally, it fires navigatesuccess or navigateerror events as appropriate, which other parts of the web application can respond to.

By default, using this method will cause focus to reset when any handlers' returned promises settle. Focus will be reset to the first element with the autofocus attribute set, or the body element if the attribute isn't present. The focusReset option can be set to "manual" to avoid this behavior.

By default, using this method will delay the browser's scroll restoration logic for "traverse" or "reload" navigations, or its scroll-reset/scroll-to-a-fragment logic for "push" or "replace" navigations, until any handlers' returned promises settle. The scroll option can be set to "manual" to turn off any browser-driven scroll behavior entirely for this navigation, or scroll() can be called before the promise settles to trigger this behavior early.

This method will throw a "SecurityError" DOMException if canIntercept is false, or if isTrusted is false. It will throw an "InvalidStateError" DOMException if not called synchronously, during event dispatch.

event.scroll()

For "traverse" or "reload" navigations, restores the scroll position using the browser's usual scroll restoration logic.

For "push" or "replace" navigations, either resets the scroll position to the top of the document or scrolls to the fragment specified by destination.url if there is one.

If called more than once, or called after automatic post-transition scroll processing has happened due to the scroll option being left as "after-transition", or called before the navigation has committed, this method will throw an "InvalidStateError" DOMException.

7.2.5.9.2 The NavigationDestination interface
event.destination.url

The URL being navigated to.

event.destination.key

The value of the key property of the destination NavigationHistoryEntry, if this is a "traverse" navigation, or the empty string otherwise.

event.destination.id

The value of the id property of the destination NavigationHistoryEntry, if this is a "traverse" navigation, or the empty string otherwise.

event.destination.index

The value of the index property of the destination NavigationHistoryEntry, if this is a "traverse" navigation, or −1 otherwise.

event.destination.sameDocument

Indicates whether or not this navigation is to the same Document as the current one, or not. This will be true, for example, in the case of fragment navigations or history.pushState() navigations.

Note that this property indicates the original nature of the navigation. If a cross-document navigation is converted into a same-document navigation using navigateEvent.intercept(), that will not change the value of this property.

event.destination.getState()

For "traverse" navigations, returns the deserialization of the state stored in the destination session history entry.

For "push" or "replace" navigations, returns the deserialization of the state passed to navigation.navigate(), if the navigation was initiated by that method, or undefined it if it wasn't.

For "reload" navigations, returns the deserialization of the state passed to navigation.reload(), if the reload was initiated by that method, or undefined it if it wasn't.

NavigateEventインターフェイスには、その複雑さのために独自の専用セクションを持つ。

7.2.6.1 NavigationCurrentEntryChangeEventインターフェイス
event.navigationType

現在のエントリーを変更したナビゲーションのタイプを返す。変更の原因がnavigation.updateCurrentEntry()の場合、nullを返す。

event.from

現在のエントリーが変更される前のnavigation.currentEntryの値を返す。

navigationTypeがnullまたは"reload"である場合、この値はnavigation.currentEntryと同じになる。この場合、イベントは、たとえ新しいエントリーに移動しなかった、または現在のエントリーを置き換えなかったとしても、エントリーの内容が変更されたことを示す。

7.2.6.2 PopStateEventインターフェイス

PopStateEvent/PopStateEvent

Support in all current engines.

Firefox11+Safari6+Chrome16+
Opera?Edge79+
Edge (Legacy)14+Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

PopStateEvent

Support in all current engines.

Firefox4+Safari6+Chrome4+
Opera12.1+Edge79+
Edge (Legacy)12+Internet Explorer10+
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android12.1+
event.state

pushState()またはreplaceState()へ提供される情報のコピーを返す。

event.hasUAVisualTransition

ユーザーエージェントが、このイベントをディスパッチする前に、このナビゲーションのビジュアルトランジションを実行した場合、trueを返す。trueの場合、著者がDOMをナビゲーション後の状態に同期的に更新するならば、最高のユーザーエクスペリエンスが得られる。

7.2.6.3 HashChangeEventインターフェイス

HashChangeEvent/HashChangeEvent

Support in all current engines.

Firefox11+Safari6+Chrome16+
Opera?Edge79+
Edge (Legacy)12+Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

HashChangeEvent

Support in all current engines.

Firefox3.6+Safari5+Chrome8+
Opera10.6+Edge79+
Edge (Legacy)12+Internet Explorer8+
Firefox Android?Safari iOS5+Chrome Android?WebView Android?Samsung Internet?Opera Android11+
event.oldURL

以前に現在であったセッション履歴のエントリーURLを返す。

event.newURL

今現在であるセッション履歴のエントリーURLを返す。

7.2.6.4 PageSwapEventインターフェイス
event.activation

ドキュメント間ナビゲーションの移動先と種類を表すNavigationActivationオブジェクト。異なる生成元のナビゲーションの場合はnullになる。

event.activation.entry

アクティブになるDocumentを表すNavigationHistoryEntry

event.activation.from

イベントが発火した時点でのnavigation.currentEntryプロパティの値に相当するNavigationHistoryEntry

event.activation.navigationType

"push"、"replace"、"reload"または"traverse"のいずれかで、ページスワップが行われるナビゲーションのタイプを示す。

event.viewTransition

イベントが発火したときに遷移がアクティブである場合、アウトバウンドの文書間の参照の遷移を表すViewTransitionオブジェクトを返す。そうでなければ、nullを返す。

7.2.6.5 PageRevealEventインターフェイス
event.viewTransition

イベントが発火したときに遷移がアクティブである場合、インバウンドの文書間の参照の遷移を表す ViewTransitionオブジェクトを返す。そうでなければ、nullを返す。

7.2.6.6 PageTransitionEventインターフェイス

PageTransitionEvent/PageTransitionEvent

Support in all current engines.

Firefox11+Safari6+Chrome16+
Opera?Edge79+
Edge (Legacy)?Internet ExplorerNo
Firefox Android?Safari iOS?Chrome Android?WebView Android?Samsung Internet?Opera Android?

PageTransitionEvent

Support in all current engines.

Firefox1.5+Safari5+Chrome4+
Opera?Edge79+
Edge (Legacy)12+Internet Explorer11
Firefox Android?Safari iOS4+Chrome Android?WebView Android37+Samsung Internet?Opera Android?
event.persisted

pageshowに対して、ページが新しく読み込まれている(およびloadイベントが発生する)場合にfalseを返す。そうでなければ、trueを返す。

pagehideイベントに対して、ページが最後の時間まで出かける場合はfalseを返す。そうでなければtrueを返す。これは、ユーザーがこのページに戻った場合(Documentsalvageable状態がtrueのままの場合)にページが再利用される可能性があることを意味する。

ページがサルベージ不能になる原因には、次のものがある:

7.2.6.7 BeforeUnloadEventインターフェイス

BeforeUnloadEvent

Support in all current engines.

Firefox1.5+Safari7+Chrome30+
Opera?Edge79+
Edge (Legacy)?Internet Explorer4+
Firefox Android?Safari iOS?Chrome Android?WebView Android37+Samsung Internet3.0+Opera Android?

BeforeUnloadEvent固有の初期化メソッドは存在しない。

BeforeUnloadEventインターフェイスは、イベントをキャンセルするだけでなく、returnValue属性を空文字列以外の値に設定することで、アンロードがキャンセルされたかどうかをチェックできるようにするレガシーインターフェイスである。著者は、returnValueを使用する代わりに、preventDefault()メソッド、またはイベントをキャンセルするその他の手段を使用すべきである。

7.2.7 The NotRestoredReasons interface

notRestoredReasonDetails.reason

Returns a string that explains the reason that prevented the document from being served from back/forward cache. See the definition of bfcache blocking details for the possible string values.

notRestoredReasons.src

Returns the src attribute of the document's node navigable's container if it is an iframe element. This can be null if not set or if it is not an iframe element.

notRestoredReasons.id

Returns the id attribute of the document's node navigable's container if it is an iframe element. This can be null if not set or if it is not an iframe element.

notRestoredReasons.name

Returns the name attribute of the document's node navigable's container if it is an iframe element. This can be null if not set or if it is not an iframe element.

notRestoredReasons.url

Returns the document's URL, or null if the document is in a cross-origin iframe. This is reported in addition to src because it is possible iframe navigated since the original src was set.

notRestoredReasons.reasons

Returns an array of NotRestoredReasonDetails for the document. This is null if the document is in a cross-origin iframe.

notRestoredReasons.children

Returns an array of NotRestoredReasons that are for the document’s children. This is null if the document is in a cross-origin iframe.

A NotRestoredReasonDetails object has a backing struct, a not restored reason details or null, initially null.

The reason getter steps are to return this's backing struct's reason.

To create a NotRestoredReasonDetails object given a not restored reason details backingStruct and a realm realm:

  1. Let notRestoredReasonDetails be a new NotRestoredReasonDetails object created in realm.

  2. Set notRestoredReasonDetails's backing struct to backingStruct.

  3. Return notRestoredReasonDetails.

A not restored reason details is a struct with the following items:

The reason is a string that represents the reason that prevented the page from being restored from back/forward cache. The string is one of the following:

"fetch"
While unloading, a fetch initiated by this Document was still ongoing and was canceled, so the page was not in a state that could be stored in the back/forward cache.
"navigation-failure"
The original navigation that created this Document errored, so storing the resulting error document in the back/forward cache was prevented.
"parser-aborted"
The Document never finished its initial HTML parsing, so storing the unfinished document in the back/forward cache was prevented.
"websocket"
While unloading, an open WebSocket connection was shut down, so the page was not in a state that could be stored in the back/forward cache. [WEBSOCKETS]
"lock"
While unloading, held locks and lock requests were terminated, so the page was not in a state that could be stored in the back/forward cache. [WEBLOCKS]
"masked"
This Document has children that are in a cross-origin iframe, and they prevented back/forward cache; or this Document could not be back/forward cached for user agent-specific reasons, and the user agent has chosen not to use one of the more specific reasons from the list of user-agent specific blocking reasons.

In addition to the list above, a user agent might choose to expose a reason that prevented the page from being restored from back/forward cache for user-agent specific blocking reasons. These are one of the following strings:

"audio-capture"
The Document requested audio capture permission by using Media Capture and Streams's getUserMedia() with audio. [MEDIASTREAM]
"background-work"
The Document requested background work by calling SyncManager's register() method, PeriodicSyncManager's register() method, or BackgroundFetchManager's fetch() method.
"broadcastchannel-message"
While the page was stored in back/forward cache, a BroadcastChannel connection on the page received a message and message event was fired.
"idbversionchangeevent"
The Document had a pending IDBVersionChangeEvent while unloading. [INDEXEDDB]
"idledetector"
The Document had an active IdleDetector while unloading.
"keyboardlock"
While unloading, keyboard lock was still active because Keyboard's lock() method was called.
"mediastream"
A MediaStreamTrack was in the live state upon unloading. [MEDIASTREAM]
"midi"
The Document requested a MIDI permission by calling navigator.requestMIDIAccess().
"modals"
User prompts were shown while unloading.
"navigating"
While unloading, loading was still ongoing, and so the Document was not in a state that could be stored in back/forward cache.
"navigation-canceled"
The navigation request was canceled by calling window.stop() and the page was not in a state to be stored in back/forward cache.
"non-trivial-browsing-context-group"
The browsing context group of this Document had more than one top-level browsing context.
"otpcredential"
The Document created an OTPCredential.
"outstanding-network-request"
While unloading, the Document had outstanding network requests and was not in a state that could be stored in back/forward cache.
"paymentrequest"
The Document had an active PaymentRequest while unloading. [PAYMENTREQUEST]
"pictureinpicturewindow"
The Document had an active PictureInPictureWindow while unloading. [PICTUREINPICTURE]
"plugins"
The Document contained plugins.
"request-method-not-get"
The Document was created from an HTTP request whose method was not `GET`. [FETCH]
"response-auth-required"
The Document was created from an HTTP response that required HTTP authentication.
"response-cache-control-no-store"
The Document was created from an HTTP response whose `Cache-Control` header included the "no-store" token. [HTTP]
"response-cache-control-no-cache"
The Document was created from an HTTP response whose `Cache-Control` header included the "no-cache" token. [HTTP]
"response-keep-alive"
The Document was created from an HTTP response that contained a `Keep-Alive` header.
"response-scheme-not-http-or-https"
The Document was created from a response whose URL's scheme was not an HTTP(S) scheme. [FETCH]
"response-status-not-ok"
The Document was created from an HTTP response whose status was not an ok status. [FETCH]
"rtc"
While unloading, a RTCPeerConnection or RTCDataChannel was shut down, so the page was not in a state that could be stored in the back/forward cache. [WEBRTC]
"sensors"
The Document requested sensor access.
"serviceworker-added"
The Document's service worker client started to be controlled by a ServiceWorker while the page was in back/forward cache. [SW]
"serviceworker-claimed"
The Document's service worker client's active service worker was claimed while the page was in back/forward cache. [SW]
"serviceworker-postmessage"
The Document's service worker client's active service worker received a message while the page was in back/forward cache. [SW]
"serviceworker-version-activated"
The Document's service worker client's active service worker's version was activated while the page was in back/forward cache. [SW]
"serviceworker-unregistered"
The Document's service worker client's active service worker's service worker registration was unregistered while the page was in back/forward cache. [SW]
"sharedworker"
This Document was in the owner set of a SharedWorkerGlobalScope.
"smartcardconnection"
The Document had an active SmartCardConnection while unloading.
"speechrecognition"
The Document had an active SpeechRecognition while unloading.
"storageaccess"
The Document requested storage access permission by using the Storage Access API.
"unload-listener"
The Document registered an event listener for the unload event.
"video-capture"
The Document requested video capture permission by using Media Capture and Streams's getUserMedia() with video. [MEDIASTREAM]
"webhid"
The Document called the WebHID API's requestDevice() method.
"webshare"
The Document used the Web Share API's navigator.share() method.
"webtransport"
While unloading, an open WebTransport connection was shut down, so the page was not in a state that could be stored in the back/forward cache. [WEBTRANSPORT]
"webxrdevice"
The Document created a XRSystem.

A NotRestoredReasons object has a backing struct, a not restored reasons or null, initially null.

A NotRestoredReasons object has a reasons array, a FrozenArray<NotRestoredReasonDetails> or null, initially null.

A NotRestoredReasons object has a children array, a FrozenArray<NotRestoredReasons> or null, initially null.

The src getter steps are to return this's backing struct's src.

The id getter steps are to return this's backing struct's id.

The name getter steps are to return this's backing struct's name.

The url getter steps are:

  1. If this's backing struct's URL is null, then return null.

  2. Return this's backing struct's URL, serialized.

The reasons getter steps are to return this's reasons array.

The children getter steps are to return this's children array.

To create a NotRestoredReasons object given a not restored reasons backingStruct and a realm realm:

  1. Let notRestoredReasons be a new NotRestoredReasons object created in realm.

  2. Set notRestoredReasons's backing struct to backingStruct.

  3. If backingStruct's reasons is null, set notRestoredReasons's reasons array to null.

  4. Otherwise:

    1. Let reasonsArray be an empty list.

    2. For each reason of backingStruct's reasons:

      1. Create a NotRestoredReasonDetails object given reason and realm, and append it to reasonsArray.

    3. Set notRestoredReasons's reasons array to the result of creating a frozen array given reasonsArray.

  5. If backingStruct's children is null, set notRestoredReasons's children array to null.

  6. Otherwise:

    1. Let childrenArray be an empty list.

    2. For each child of backingStruct's children:

      1. Create a NotRestoredReasons object given child and realm and append it to childrenArray.

    3. Set notRestoredReasons's children array to the result of creating a frozen array given childrenArray.

  7. Return notRestoredReasons.

A not restored reasons is a struct with the following items:

A Document's not restored reasons is its node navigable's active session history entry's document state's not restored reasons, if Document's node navigable is a top-level traversable; otherwise null.