// waiting for tasks from background
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
const item = msg.item;
// Asynchronously process your "item", but DON'T return the promise
asyncOperation().then(() => {
// telling that CS has finished its job
sendResponse({complete: true});
});
// return true from the event listener to indicate you wish to send a response asynchronously
// (this will keep the message channel open to the other end until sendResponse is called).
return true;
});
/**
* Promise wrapper for chrome.tabs.sendMessage
* @param tabId
* @param item
* @returns {Promise<any>}
*/
function sendMessagePromise(tabId, item) {
return new Promise((resolve, reject) => {
chrome.tabs.sendMessage(tabId, {item}, response => {
if(response.complete) {
resolve();
} else {
reject('Something wrong');
}
});
});
}
Code Example |
---|
Javascript :: |
Javascript :: |
:: how to add array of object in class in javascript |
Javascript :: |
:: |
:: optional validation vuetify |
:: |
Javascript :: |
:: |
:: |
:: |
:: |
:: js to jquery ONLINE converter |
:: |
:: |
Javascript :: |
:: |
Javascript :: duplicate serial numbers asset |
Javascript :: crypto digest node.js |
:: |
Javascript :: how to parse arguments to a promise in javascript |
:: composer json schema download |
:: |
Javascript :: javascript use numbers as objects |
:: blue pring GUI react |
Javascript :: |
Javascript :: |
:: |
Javascript :: JavaScript combining rows of multiple datasets |
:: html document from string javascript |