feat: Restore webContents navigation history and page state (#45583)
* feat: Working navigationHistory.restore with just title/url Co-authored-by: Felix Rieseberg <fr@makenotion.com> * feat: Restore page state, too Co-authored-by: Felix Rieseberg <fr@makenotion.com> * chore: Docs, lint, tests Co-authored-by: Felix Rieseberg <fr@makenotion.com> * Implement feedback Co-authored-by: Felix Rieseberg <fr@makenotion.com> * More magic Co-authored-by: Felix Rieseberg <fr@makenotion.com> * Make _awaitNextLoad truly private Co-authored-by: Felix Rieseberg <fr@makenotion.com> * Implement API group feedback Co-authored-by: Felix Rieseberg <fr@makenotion.com> * One more round of feedback Co-authored-by: Felix Rieseberg <fr@makenotion.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Felix Rieseberg <fr@makenotion.com>
This commit is contained in:
parent
b2b59a6c0b
commit
9a7f27d845
8 changed files with 259 additions and 10 deletions
|
@ -74,3 +74,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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue