fix: ensure the webContents is not destroyed before communicating (#18467)
This commit is contained in:
parent
815b9d7707
commit
93b8dc2362
1 changed files with 5 additions and 3 deletions
|
@ -115,8 +115,10 @@ const removeBackgroundPages = function (manifest) {
|
||||||
|
|
||||||
const sendToBackgroundPages = function (...args) {
|
const sendToBackgroundPages = function (...args) {
|
||||||
for (const page of Object.values(backgroundPages)) {
|
for (const page of Object.values(backgroundPages)) {
|
||||||
|
if (!page.webContents.isDestroyed()) {
|
||||||
page.webContents._sendInternalToAll(...args)
|
page.webContents._sendInternalToAll(...args)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dispatch web contents events to Chrome APIs
|
// Dispatch web contents events to Chrome APIs
|
||||||
|
@ -161,7 +163,7 @@ ipcMainUtils.handle('CHROME_RUNTIME_CONNECT', function (event, extensionId, conn
|
||||||
}
|
}
|
||||||
|
|
||||||
const page = backgroundPages[extensionId]
|
const page = backgroundPages[extensionId]
|
||||||
if (!page) {
|
if (!page || page.webContents.isDestroyed()) {
|
||||||
throw new Error(`Connect to unknown extension ${extensionId}`)
|
throw new Error(`Connect to unknown extension ${extensionId}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +193,7 @@ ipcMainUtils.handle('CHROME_RUNTIME_SEND_MESSAGE', async function (event, extens
|
||||||
}
|
}
|
||||||
|
|
||||||
const page = backgroundPages[extensionId]
|
const page = backgroundPages[extensionId]
|
||||||
if (!page) {
|
if (!page || page.webContents.isDestroyed()) {
|
||||||
throw new Error(`Connect to unknown extension ${extensionId}`)
|
throw new Error(`Connect to unknown extension ${extensionId}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue