feat: duplicate navigation related APIs to contents.navigationHistory (#41752)

* refactor: move navigation related api to navigationHistory

* docs: add deprecation messages to old web content methods

* fix: add deprecation warnings to webcontents

* fix: add deprecation warnings and make existing naviagation apis internal

* Update docs/api/web-contents.md

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>

* Update docs/api/web-contents.md

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>

* Update docs/api/web-contents.md

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>

* Update docs/api/web-contents.md

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>

* docs: fix links

* docs: add breaking change to 31

* docs: move breaking change to 32

* chore: re-run pipeline

---------

Co-authored-by: Sam Maddock <samuel.maddock@gmail.com>
This commit is contained in:
Alice Zhao 2024-06-05 09:34:47 -07:00 committed by GitHub
parent 5fb117a7d7
commit 406f644d26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 239 additions and 17 deletions

View file

@ -9,6 +9,24 @@ Each navigation entry corresponds to a specific page. The indexing system follow
### Instance Methods
#### `navigationHistory.canGoBack()`
Returns `boolean` - Whether the browser can go back to previous web page.
#### `navigationHistory.canGoForward()`
Returns `boolean` - Whether the browser can go forward to next web page.
#### `navigationHistory.canGoToOffset(offset)`
* `offset` Integer
Returns `boolean` - Whether the web page can go to the specified `offset` from the current entry.
#### `navigationHistory.clear()`
Clears the navigation history.
#### `navigationHistory.getActiveIndex()`
Returns `Integer` - The index of the current page, from which we would go back/forward or reload.
@ -24,6 +42,26 @@ Returns `Object`:
If index is out of bounds (greater than history length or less than 0), null will be returned.
#### `navigationHistory.goBack()`
Makes the browser go back a web page.
#### `navigationHistory.goForward()`
Makes the browser go forward a web page.
#### `navigationHistory.goToIndex(index)`
* `index` Integer
Navigates browser to the specified absolute web page index.
#### `navigationHistory.goToOffset(offset)`
* `offset` Integer
Navigates to the specified offset from the current entry.
#### `navigationHistory.length()`
Returns `Integer` - History length.

View file

@ -1124,44 +1124,60 @@ Reloads the current web page.
Reloads current page and ignores cache.
#### `contents.canGoBack()`
#### `contents.canGoBack()` _Deprecated_
Returns `boolean` - Whether the browser can go back to previous web page.
#### `contents.canGoForward()`
**Deprecated:** Should use the new [`contents.navigationHistory.canGoBack`](navigation-history.md#navigationhistorycangoback) API.
#### `contents.canGoForward()` _Deprecated_
Returns `boolean` - Whether the browser can go forward to next web page.
#### `contents.canGoToOffset(offset)`
**Deprecated:** Should use the new [`contents.navigationHistory.canGoForward`](navigation-history.md#navigationhistorycangoforward) API.
#### `contents.canGoToOffset(offset)` _Deprecated_
* `offset` Integer
Returns `boolean` - Whether the web page can go to `offset`.
#### `contents.clearHistory()`
**Deprecated:** Should use the new [`contents.navigationHistory.canGoToOffset`](navigation-history.md#navigationhistorycangotooffsetoffset) API.
#### `contents.clearHistory()` _Deprecated_
Clears the navigation history.
#### `contents.goBack()`
**Deprecated:** Should use the new [`contents.navigationHistory.clear`](navigation-history.md#navigationhistoryclear) API.
#### `contents.goBack()` _Deprecated_
Makes the browser go back a web page.
#### `contents.goForward()`
**Deprecated:** Should use the new [`contents.navigationHistory.goBack`](navigation-history.md#navigationhistorygoback) API.
#### `contents.goForward()` _Deprecated_
Makes the browser go forward a web page.
#### `contents.goToIndex(index)`
**Deprecated:** Should use the new [`contents.navigationHistory.goForward`](navigation-history.md#navigationhistorygoforward) API.
#### `contents.goToIndex(index)` _Deprecated_
* `index` Integer
Navigates browser to the specified absolute web page index.
#### `contents.goToOffset(offset)`
**Deprecated:** Should use the new [`contents.navigationHistory.goToIndex`](navigation-history.md#navigationhistorygotoindexindex) API.
#### `contents.goToOffset(offset)` _Deprecated_
* `offset` Integer
Navigates to the specified offset from the "current entry".
**Deprecated:** Should use the new [`contents.navigationHistory.goToOffset`](navigation-history.md#navigationhistorygotooffsetoffset) API.
#### `contents.isCrashed()`
Returns `boolean` - Whether the renderer process has crashed.

View file

@ -44,6 +44,32 @@ contextBridge.exposeInMainWorld('electron', {
})
```
### Deprecated: `clearHistory`, `canGoBack`, `goBack`, `canGoForward`, `goForward`, `canGoToOffset`, `goToOffset` on `WebContents`
The navigation-related APIs are now deprecated.
These APIs have been moved to the `navigationHistory` property of `WebContents` to provide a more structured and intuitive interface for managing navigation history.
```js
// Deprecated
win.webContents.clearHistory()
win.webContents.canGoBack()
win.webContents.goBack()
win.webContents.canGoForward()
win.webContents.goForward()
win.webContents.canGoToOffset()
win.webContents.goToOffset(index)
// Replace with
win.webContents.navigationHistory.clear()
win.webContents.navigationHistory.canGoBack()
win.webContents.navigationHistory.goBack()
win.webContents.navigationHistory.canGoForward()
win.webContents.navigationHistory.goForward()
win.webContents.navigationHistory.canGoToOffset()
win.webContents.navigationHistory.goToOffset(index)
```
## Planned Breaking API Changes (31.0)
### Removed: `WebSQL` support
@ -52,7 +78,7 @@ Chromium has removed support for WebSQL upstream, transitioning it to Android on
[Chromium's intent to remove discussion](https://groups.google.com/a/chromium.org/g/blink-dev/c/fWYb6evVA-w/m/wGI863zaAAAJ)
for more information.
### Behavior Changed: `nativeImage.toDataURL` will preseve PNG colorspace
### Behavior Changed: `nativeImage.toDataURL` will preserve PNG colorspace
PNG decoder implementation has been changed to preserve colorspace data, the
encoded data returned from this function now matches it.