fix: send chrome.runtime/tabs.sendMessage
result to correct sender (#16945)
Additionally, use `.once` instead of `.on` for result specific listeners.
This commit is contained in:
parent
8497bb1327
commit
84ef9cae6c
2 changed files with 5 additions and 5 deletions
|
@ -186,7 +186,7 @@ ipcMainInternal.on('CHROME_RUNTIME_SENDMESSAGE', function (event, extensionId, m
|
|||
}
|
||||
|
||||
page.webContents._sendInternalToAll(`CHROME_RUNTIME_ONMESSAGE_${extensionId}`, event.sender.id, message, resultID)
|
||||
ipcMainInternal.once(`CHROME_RUNTIME_ONMESSAGE_RESULT_${resultID}`, (event, result) => {
|
||||
ipcMainInternal.once(`CHROME_RUNTIME_ONMESSAGE_RESULT_${resultID}`, (resultEvent, result) => {
|
||||
event._replyInternal(`CHROME_RUNTIME_SENDMESSAGE_RESULT_${originResultID}`, result)
|
||||
})
|
||||
resultID++
|
||||
|
@ -202,7 +202,7 @@ ipcMainInternal.on('CHROME_TABS_SEND_MESSAGE', function (event, tabId, extension
|
|||
const senderTabId = isBackgroundPage ? null : event.sender.id
|
||||
|
||||
contents._sendInternalToAll(`CHROME_RUNTIME_ONMESSAGE_${extensionId}`, senderTabId, message, resultID)
|
||||
ipcMainInternal.once(`CHROME_RUNTIME_ONMESSAGE_RESULT_${resultID}`, (event, result) => {
|
||||
ipcMainInternal.once(`CHROME_RUNTIME_ONMESSAGE_RESULT_${resultID}`, (resultEvent, result) => {
|
||||
event._replyInternal(`CHROME_TABS_SEND_MESSAGE_RESULT_${originResultID}`, result)
|
||||
})
|
||||
resultID++
|
||||
|
|
|
@ -130,14 +130,14 @@ exports.injectTo = function (extensionId, isBackgroundPage, context) {
|
|||
} else if (args.length === 2) {
|
||||
// A case of not provide extension-id: (message, responseCallback)
|
||||
if (typeof args[1] === 'function') {
|
||||
ipcRenderer.on(`CHROME_RUNTIME_SENDMESSAGE_RESULT_${originResultID}`, (event, result) => args[1](result))
|
||||
ipcRenderer.once(`CHROME_RUNTIME_SENDMESSAGE_RESULT_${originResultID}`, (event, result) => args[1](result))
|
||||
message = args[0]
|
||||
} else {
|
||||
[targetExtensionId, message] = args
|
||||
}
|
||||
} else {
|
||||
console.error('options is not supported')
|
||||
ipcRenderer.on(`CHROME_RUNTIME_SENDMESSAGE_RESULT_${originResultID}`, (event, result) => args[2](result))
|
||||
ipcRenderer.once(`CHROME_RUNTIME_SENDMESSAGE_RESULT_${originResultID}`, (event, result) => args[2](result))
|
||||
}
|
||||
|
||||
ipcRenderer.send('CHROME_RUNTIME_SENDMESSAGE', targetExtensionId, message, originResultID)
|
||||
|
@ -160,7 +160,7 @@ exports.injectTo = function (extensionId, isBackgroundPage, context) {
|
|||
|
||||
sendMessage (tabId, message, options, responseCallback) {
|
||||
if (responseCallback) {
|
||||
ipcRenderer.on(`CHROME_TABS_SEND_MESSAGE_RESULT_${originResultID}`, (event, result) => responseCallback(result))
|
||||
ipcRenderer.once(`CHROME_TABS_SEND_MESSAGE_RESULT_${originResultID}`, (event, result) => responseCallback(result))
|
||||
}
|
||||
ipcRenderer.send('CHROME_TABS_SEND_MESSAGE', tabId, extensionId, isBackgroundPage, message, originResultID)
|
||||
originResultID++
|
||||
|
|
Loading…
Add table
Reference in a new issue