-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added support for the sendResponse callback in the runtime.onMe…
…ssage listeners (#97)
- Loading branch information
Showing
5 changed files
with
209 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
const {name} = browser.runtime.getManifest(); | ||
|
||
async function runTest() { | ||
let reply; | ||
reply = await browser.runtime.sendMessage("test - sendMessage with returned Promise reply"); | ||
console.log(name, "test - returned resolved Promise - received", reply); | ||
|
||
reply = await browser.runtime.sendMessage("test - sendMessage with returned value reply"); | ||
console.log(name, "test - returned value - received", reply); | ||
|
||
reply = await browser.runtime.sendMessage("test - sendMessage with synchronous sendResponse"); | ||
console.log(name, "test - synchronous sendResponse - received", reply); | ||
|
||
reply = await browser.runtime.sendMessage("test - sendMessage with asynchronous sendResponse"); | ||
console.log(name, "test - asynchronous sendResponse - received", reply); | ||
|
||
reply = await browser.runtime.sendMessage("test - second listener if the first does not reply"); | ||
console.log(name, "test - second listener sendResponse - received", reply); | ||
|
||
console.log(name, "content script messages sent"); | ||
} | ||
|
||
console.log(name, "content script loaded"); | ||
|
||
browser.runtime.sendMessage("content script message").then(reply => { | ||
console.log(name, "content script received reply", {reply}); | ||
runTest().catch((err) => { | ||
console.error("content script error", err); | ||
}); | ||
|
||
console.log(name, "content script message sent"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters