fix: redirect webview navigation methods (#43082)
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Alice Zhao <alice@makenotion.com>
This commit is contained in:
parent
9d67e1d72e
commit
2ef1c6dc49
2 changed files with 22 additions and 10 deletions
|
@ -2,7 +2,7 @@ import { webContents } from 'electron/main';
|
||||||
import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal';
|
import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal';
|
||||||
import * as ipcMainUtils from '@electron/internal/browser/ipc-main-internal-utils';
|
import * as ipcMainUtils from '@electron/internal/browser/ipc-main-internal-utils';
|
||||||
import { parseWebViewWebPreferences } from '@electron/internal/browser/parse-features-string';
|
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 { webViewEvents } from '@electron/internal/browser/web-view-events';
|
||||||
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
|
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)) {
|
if (!syncMethods.has(method)) {
|
||||||
throw new Error(`Invalid method: ${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);
|
return (guest as any)[method](...args);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,3 +1,14 @@
|
||||||
|
export const navigationHistorySyncMethods = new Set([
|
||||||
|
'canGoBack',
|
||||||
|
'canGoForward',
|
||||||
|
'canGoToOffset',
|
||||||
|
'clearHistory',
|
||||||
|
'goBack',
|
||||||
|
'goForward',
|
||||||
|
'goToIndex',
|
||||||
|
'goToOffset'
|
||||||
|
]);
|
||||||
|
|
||||||
// Public-facing API methods.
|
// Public-facing API methods.
|
||||||
export const syncMethods = new Set([
|
export const syncMethods = new Set([
|
||||||
'getURL',
|
'getURL',
|
||||||
|
@ -8,14 +19,6 @@ export const syncMethods = new Set([
|
||||||
'stop',
|
'stop',
|
||||||
'reload',
|
'reload',
|
||||||
'reloadIgnoringCache',
|
'reloadIgnoringCache',
|
||||||
'canGoBack',
|
|
||||||
'canGoForward',
|
|
||||||
'canGoToOffset',
|
|
||||||
'clearHistory',
|
|
||||||
'goBack',
|
|
||||||
'goForward',
|
|
||||||
'goToIndex',
|
|
||||||
'goToOffset',
|
|
||||||
'isCrashed',
|
'isCrashed',
|
||||||
'setUserAgent',
|
'setUserAgent',
|
||||||
'getUserAgent',
|
'getUserAgent',
|
||||||
|
@ -51,7 +54,8 @@ export const syncMethods = new Set([
|
||||||
'getZoomFactor',
|
'getZoomFactor',
|
||||||
'getZoomLevel',
|
'getZoomLevel',
|
||||||
'setZoomFactor',
|
'setZoomFactor',
|
||||||
'setZoomLevel'
|
'setZoomLevel',
|
||||||
|
...navigationHistorySyncMethods
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const properties = new Set([
|
export const properties = new Set([
|
||||||
|
|
Loading…
Add table
Reference in a new issue