Repository: electron/electron
Pull request: fix: redirect webview navigation methods

#### Description of Change

This PR fixes https://github.com/electron/electron/issues/42879

<!--
Thank you for your Pull Request. Please provide a description above and review
the requirements below.

Contributors guide: https://github.com/electron/electron/blob/main/CONTRIBUTING.md
-->

#### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] PR description included and stakeholders cc'd
- [x] `npm test` passes
- [x] tests are [changed or added](https://github.com/electron/electron/blob/main/docs/development/testing.md)
- [x] relevant documentation, tutorials, templates and examples are changed or added
- [x] [PR release notes](https://github.com/electron/clerk/blob/main/README.md) describe the change in a way relevant to app developers, and are [capitalized, punctuated, and past tense](https://github.com/electron/clerk/blob/main/README.md#examples).

Testing:

Before changes, tests show deprecation warning:
<img width="973" alt="image" src="https://github.com/user-attachments/assets/395d011b-5d76-48dc-8106-8a1448fb8075">

After changes, deprecation warnings are gone:
<img width="973" alt="image" src="https://github.com/user-attachments/assets/5c2cbbd4-36bd-4d56-b61f-f6357b56af43">


#### Release Notes

Notes: none


Changed files:
filename: lib/browser/guest-view-manager.ts
patch: @@ -2,7 +2,7 @@ import { webContents } from 'electron/main';
 import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal';
 import * as ipcMainUtils from '@electron/internal/browser/ipc-main-internal-utils';
 import { parseWebViewWebPreferences } from '@electron/internal/browser/parse-features-string';
-import { syncMethods, asyncMethods, properties } from '@electron/internal/common/web-view-methods';
+import { syncMethods, asyncMethods, properties, navigationHistorySyncMethods } from '@electron/internal/common/web-view-methods';
 import { webViewEvents } from '@electron/internal/browser/web-view-events';
 import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
 
@@ -311,6 +311,14 @@ handleMessageSync(IPC_MESSAGES.GUEST_VIEW_MANAGER_CALL, function (event, guestIn
   if (!syncMethods.has(method)) {
     throw new Error(`Invalid method: ${method}`);
   }
+  // Redirect history methods to updated navigationHistory property on webContents. See issue #42879.
+  if (navigationHistorySyncMethods.has(method)) {
+    let navigationMethod = method;
+    if (method === 'clearHistory') {
+      navigationMethod = 'clear';
+    }
+    return (guest as any).navigationHistory[navigationMethod](...args);
+  }
 
   return (guest as any)[method](...args);
 });

filename: lib/common/web-view-methods.ts
patch: @@ -1,3 +1,14 @@
+export const navigationHistorySyncMethods = new Set([
+  'canGoBack',
+  'canGoForward',
+  'canGoToOffset',
+  'clearHistory',
+  'goBack',
+  'goForward',
+  'goToIndex',
+  'goToOffset'
+]);
+
 // Public-facing API methods.
 export const syncMethods = new Set([
   'getURL',
@@ -8,14 +19,6 @@ export const syncMethods = new Set([
   'stop',
   'reload',
   'reloadIgnoringCache',
-  'canGoBack',
-  'canGoForward',
-  'canGoToOffset',
-  'clearHistory',
-  'goBack',
-  'goForward',
-  'goToIndex',
-  'goToOffset',
   'isCrashed',
   'setUserAgent',
   'getUserAgent',
@@ -51,7 +54,8 @@ export const syncMethods = new Set([
   'getZoomFactor',
   'getZoomLevel',
   'setZoomFactor',
-  'setZoomLevel'
+  'setZoomLevel',
+  ...navigationHistorySyncMethods
 ]);
 
 export const properties = new Set([