Skip to content

Commit

Permalink
chore: update ref to docs (🤖)
Browse files Browse the repository at this point in the history
  • Loading branch information
1 parent 9e7ab80 commit d54b4bb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/latest/.sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c1918f96cb88b61be2b54589f98038c01a0881de
ddc7afd3f006dab49a3b6bf73bf3222b017556d5
19 changes: 19 additions & 0 deletions docs/latest/api/navigation-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,22 @@ Returns `boolean` - Whether the navigation entry was removed from the webContent
#### `navigationHistory.getAllEntries()`

Returns [`NavigationEntry[]`](structures/navigation-entry.md) - WebContents complete history.

#### `navigationHistory.restore(options)`

Restores navigation history and loads the given entry in the in stack. Will make a best effort
to restore not just the navigation stack but also the state of the individual pages - for instance
including HTML form values or the scroll position. It's recommended to call this API before any
navigation entries are created, so ideally before you call `loadURL()` or `loadFile()` on the
`webContents` object.

This API allows you to create common flows that aim to restore, recreate, or clone other webContents.

* `options` Object
* `entries` [NavigationEntry[]](structures/navigation-entry.md) - Result of a prior `getAllEntries()` call
* `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.

Returns `Promise<void>` - the promise will resolve when the page has finished loading the selected navigation entry
(see [`did-finish-load`](web-contents.md#event-did-finish-load)), and rejects
if the page fails to load (see
[`did-fail-load`](web-contents.md#event-did-fail-load)). A noop rejection handler is already attached, which avoids unhandled rejection errors.
3 changes: 3 additions & 0 deletions docs/latest/api/structures/navigation-entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ hide_title: false

* `url` string
* `title` string
* `pageState` string (optional) - A base64 encoded data string containing Chromium page state
including information like the current scroll position or form values. It is committed by
Chromium before a navigation event and on a regular interval.
19 changes: 18 additions & 1 deletion docs/latest/tutorial/navigation-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,25 @@ if (navigationHistory.canGoToOffset(2)) {
}
```

## Restoring history

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.

```js @ts-type={navigationHistory:Electron.NavigationHistory}

const firstWindow = new BrowserWindow()

// Later, you want a second window to have the same history and navigation position
async function restore () {
const entries = firstWindow.webContents.navigationHistory.getAllEntries()
const index = firstWindow.webContents.navigationHistory.getActiveIndex()

const secondWindow = new BrowserWindow()
await secondWindow.webContents.navigationHistory.restore({ index, entries })
}
```

Here's a full example that you can open with Electron Fiddle:

```fiddle docs/latest/fiddles/features/navigation-history
```

0 comments on commit d54b4bb

Please sign in to comment.