chrome.runtime.onMessage response with async await

后端 未结 4 1844
闹比i
闹比i 2021-02-05 04:03

I want to use async await in an onMessage listener:

chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) =>{
    var key = await getKey(         


        
4条回答
  •  甜味超标
    2021-02-05 04:51

    you could try this

    chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
      new Promise(async send => {
         
    
        var key = await getKey();
        send(key);
    
    
      }).then(sendResponse)
      return true;
    });
    

提交回复
热议问题