Skip to content

Instantly share code, notes, and snippets.

@wbamberg
Created January 3, 2017 23:37
Show Gist options
  • Save wbamberg/750c26db8a5fd5253d88b08066a7a54b to your computer and use it in GitHub Desktop.
Save wbamberg/750c26db8a5fd5253d88b08066a7a54b to your computer and use it in GitHub Desktop.
// background-script.js
var responseCallback;
function respondAsync() {
setTimeout(() => {
responseCallback({response: "async response from background script"});
}, 1000);
}
function handleMessage(request, sender, sendResponse) {
console.log(`content script sent a message: ${request.content}`);
responseCallback = sendResponse;
respondAsync();
return true;
}
browser.runtime.onMessage.addListener(handleMessage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment