Chrome Extension Message passing: response not sent

前端 未结 3 1844
挽巷
挽巷 2020-11-21 06:14

I am trying to pass messages between content script and the extension

Here is what I have in content-script

chrome.runtime.sendMessage({type: \"getUr         


        
3条回答
  •  名媛妹妹
    2020-11-21 07:05

    You can use my library https://github.com/lawlietmester/webextension to make this work in both Chrome and FF with Firefox way without callbacks.

    Your code will look like:

    Browser.runtime.onMessage.addListener( request => new Promise( resolve => {
        if( !request || typeof request !== 'object' || request.type !== "getUrls" ) return;
    
        $.ajax({
            'url': "http://localhost:3000/urls",
            'method': 'GET'
        }).then( urls => { resolve({ urls }); });
    }) );
    

提交回复
热议问题