Skip to content

Commit d54b4bb

Browse files
chore: update ref to docs (🤖)
1 parent 9e7ab80 commit d54b4bb

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

‎docs/latest/.sha

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c1918f96cb88b61be2b54589f98038c01a0881de
1+
ddc7afd3f006dab49a3b6bf73bf3222b017556d5

‎docs/latest/api/navigation-history.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,22 @@ Returns `boolean` - Whether the navigation entry was removed from the webContent
8181
#### `navigationHistory.getAllEntries()`
8282

8383
Returns [`NavigationEntry[]`](structures/navigation-entry.md) - WebContents complete history.
84+
85+
#### `navigationHistory.restore(options)`
86+
87+
Restores navigation history and loads the given entry in the in stack. Will make a best effort
88+
to restore not just the navigation stack but also the state of the individual pages - for instance
89+
including HTML form values or the scroll position. It's recommended to call this API before any
90+
navigation entries are created, so ideally before you call `loadURL()` or `loadFile()` on the
91+
`webContents` object.
92+
93+
This API allows you to create common flows that aim to restore, recreate, or clone other webContents.
94+
95+
* `options` Object
96+
* `entries` [NavigationEntry[]](structures/navigation-entry.md) - Result of a prior `getAllEntries()` call
97+
* `index` Integer (optional) - Index of the stack that should be loaded. If you set it to `0`, the webContents will load the first (oldest) entry. If you leave it undefined, Electron will automatically load the last (newest) entry.
98+
99+
Returns `Promise<void>` - the promise will resolve when the page has finished loading the selected navigation entry
100+
(see [`did-finish-load`](web-contents.md#event-did-finish-load)), and rejects
101+
if the page fails to load (see
102+
[`did-fail-load`](web-contents.md#event-did-fail-load)). A noop rejection handler is already attached, which avoids unhandled rejection errors.

‎docs/latest/api/structures/navigation-entry.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ hide_title: false
99

1010
* `url` string
1111
* `title` string
12+
* `pageState` string (optional) - A base64 encoded data string containing Chromium page state
13+
including information like the current scroll position or form values. It is committed by
14+
Chromium before a navigation event and on a regular interval.

‎docs/latest/tutorial/navigation-history.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,25 @@ if (navigationHistory.canGoToOffset(2)) {
6969
}
7070
```
7171

72+
## Restoring history
73+
74+
A common flow is that you want to restore the history of a webContents - for instance to implement an "undo close tab" feature. To do so, you can call `navigationHistory.restore({ index, entries })`. This will restore the webContent's navigation history and the webContents location in said history, meaning that `goBack()` and `goForward()` navigate you through the stack as expected.
75+
76+
```js @ts-type={navigationHistory:Electron.NavigationHistory}
77+
78+
const firstWindow = new BrowserWindow()
79+
80+
// Later, you want a second window to have the same history and navigation position
81+
async function restore () {
82+
const entries = firstWindow.webContents.navigationHistory.getAllEntries()
83+
const index = firstWindow.webContents.navigationHistory.getActiveIndex()
84+
85+
const secondWindow = new BrowserWindow()
86+
await secondWindow.webContents.navigationHistory.restore({ index, entries })
87+
}
88+
```
89+
7290
Here's a full example that you can open with Electron Fiddle:
7391

7492
```fiddle docs/latest/fiddles/features/navigation-history
75-
7693
```

0 commit comments

Comments
 (0)