Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

chrome extension sendmessage await until 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;
});
Comment

chrome extension sendmessage await until 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');
            }
        });
    });
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: remove object id from the specific id 
Javascript :: ternary operator return date greeting 
Javascript :: es6 parameter destructuring nested object 
Javascript :: how to save js object to clipboard 
Javascript :: javascript to jquery converter tool 
Javascript :: how to append response header in node in every request 
Javascript :: node sass version 6.0.0 is incompatible with 4.0.0 
Javascript :: datetimepicker how to display only current motnh 
Javascript :: pass image as props vue vuetify 
Javascript :: launch chrome in incognito and dev tools 
Javascript :: firebase iterate object 
Javascript :: useEffect not working array changes 
Javascript :: node.js vds connection was aborted 
Javascript :: render eror cant find variable: react 
Javascript :: vue unit tests form submit 
Javascript :: Audio Stream from Server through Scoket 
Javascript :: ngreadonly 
Javascript :: jQuery form upload 
Javascript :: unban command discord.js v12 
Javascript :: illegal start of expression spring boot 
Javascript :: redux counter 
Javascript :: how to create image object in javascript 
Javascript :: In React Router v6, activeStyle will be removed and you should use the function style to apply inline styles to either active or inactive NavLink components. 
Javascript :: limit ajax request 
Javascript :: desc sorting in array of objects javascript 
Javascript :: delete head array js 
Javascript :: curl --post with api 
Javascript :: javascript border textbox 
Javascript :: Return Function As Parameter For Self Invoking Function 
Javascript :: Function Returning This 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =