“Chrome Extension SendMessage czeka na GetData” Kod odpowiedzi

Chrome Extension SendMessage czeka na GetData

/**
 * 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');
            }
        });
    });
}
Wicked Worm

Chrome Extension SendMessage czeka na GetData

// 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;
});
Wicked Worm

Odpowiedzi podobne do “Chrome Extension SendMessage czeka na GetData”

Pytania podobne do “Chrome Extension SendMessage czeka na GetData”

Więcej pokrewnych odpowiedzi na “Chrome Extension SendMessage czeka na GetData” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu