Port error: Could not establish connection. Receiving end does not exist. In Chromiume

前端 未结 17 2403
甜味超标
甜味超标 2020-12-05 09:26

I\'m developing an extension in Chrome, and there\'s a problem. In my inject.js, I make a request like:

chrome.extension.sendRequest({command:         


        
17条回答
  •  鱼传尺愫
    2020-12-05 09:44

    If the message handling is in a pop-up window or html page that is not always visible, before I send any message, I check if the pop-up is visible, like so:

    function isPopupVisible() { //required for firefox before sending any message ore we get the stupid message 'receiveing end does not exist'
        var views = chrome.extension.getViews({ type: "popup" }); //https://stackoverflow.com/questions/8920953/how-determine-if-the-popup-page-is-open-or-not
        if (views.length > 0) {
            console.log("Popup is visible");
            return true;
        }
        return false;
    }
    

提交回复
热议问题