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
|
@ -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
Add a link
Reference in a new issue