📜  chrome 扩展 sendmessage 等待直到 getdata - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:57.384000             🧑  作者: Mango

代码示例2
/**
 * Promise wrapper for chrome.tabs.sendMessage
 * @param tabId
 * @param item
 * @returns {Promise}
 */
function sendMessagePromise(tabId, item) {
    return new Promise((resolve, reject) => {
        chrome.tabs.sendMessage(tabId, {item}, response => {
            if(response.complete) {
                resolve();
            } else {
                reject('Something wrong');
            }
        });
    });
}