Skip to content

Commit

Permalink
fix: handle _sendToFrameInternal() throwing an exception in remote/se…
Browse files Browse the repository at this point in the history
…rver.ts (#27046)
  • Loading branch information
miniak committed Dec 17, 2020
1 parent da3d21e commit a55e028
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/browser/remote/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ const finalizationRegistry = new FinalizationRegistry((fi: FinalizerInfo) => {
const ref = rendererFunctionCache.get(mapKey);
if (ref !== undefined && ref.deref() === undefined) {
rendererFunctionCache.delete(mapKey);
if (!fi.webContents.isDestroyed()) { fi.webContents._sendToFrameInternal(fi.frameId, IPC_MESSAGES.RENDERER_RELEASE_CALLBACK, fi.id[0], fi.id[1]); }
if (!fi.webContents.isDestroyed()) {
try {
fi.webContents._sendToFrameInternal(fi.frameId, IPC_MESSAGES.RENDERER_RELEASE_CALLBACK, fi.id[0], fi.id[1]);
} catch (error) {
console.warn(`_sendToFrameInternal() failed: ${error}`);
}
}
}
});

Expand Down Expand Up @@ -265,7 +271,11 @@ const unwrapArgs = function (sender: electron.WebContents, frameId: [number, num
const callIntoRenderer = function (this: any, ...args: any[]) {
let succeed = false;
if (!sender.isDestroyed()) {
succeed = sender._sendToFrameInternal(frameId, IPC_MESSAGES.RENDERER_CALLBACK, contextId, meta.id, valueToMeta(sender, contextId, args));
try {
succeed = sender._sendToFrameInternal(frameId, IPC_MESSAGES.RENDERER_CALLBACK, contextId, meta.id, valueToMeta(sender, contextId, args));
} catch (error) {
console.warn(`_sendToFrameInternal() failed: ${error}`);
}
}
if (!succeed) {
removeRemoteListenersAndLogWarning(this, callIntoRenderer);
Expand Down

0 comments on commit a55e028

Please sign in to comment.