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

前端 未结 17 2355
甜味超标
甜味超标 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:53

    This isn't always the cause, but if you have an error in your background.js, you should check this link:

    Inspect views: _generated_background_page.html
    

    in the Extensions page, which will show you any JavaScript errors.

    This was preventing my connections from getting established.

    0 讨论(0)
  • 2020-12-05 09:53

    I was seeing this problem, where my content script wasn't loading, so posting a message was never happening.

    The problem turned out to be that I had the background script inspector open and was just pushing Cmd+R (refresh), but there was a bug in my manifest.json. When I actually went to the extensions page and reloaded that page, I got the alert showing the manifest error.

    Basically, I saw this because my content scripts never loaded in the first place and I thought I was refreshing my manifest, but I wasn't.

    0 讨论(0)
  • 2020-12-05 09:54

    After some time spent on investigation I found the problem in my case.

    I'm also getting:

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

    Before explaining, I want to say that I'm using sendMessage and onMessage for communication.

    For me this error appear when I'm sending a message from the background page to one tab where my content script is running.

    My extension runs only on tabs where youtube is open. So when I'm changing some preferences I'm looking to see what tabs I have open and send a message to update updated preference.

    In a normal case it works fine, but if I have n (n >= 1) tabs with youtube open. I click in "Reload" button for extension, I change something ... youtube tabs are not refreshed and they lost message listener so I'm getting this error.

    It seems that is pretty normal.

    If I refresh youtube tabs after extension reload I don't get this error.

    I found one solution, it may not apply for all cases:

    When I had this issue my code was:

    chrome.tabs.sendMessage(tabId, {proprName: proprName, newValue: newValue}, function(response) {});
    

    Now my code is:

    chrome.tabs.sendMessage(tabId, {proprName: proprName, newValue: newValue});
    

    For my I didn't needed response callback and because that was not responding I had this error.

    0 讨论(0)
  • 2020-12-05 09:56

    I met up with this problem because I added a listener in background.js, and when invoked it would send a message to the popup page for view state update. While sometimes the listener is invoked, the popup page does not indeed exist. I check to make sure the popup page exists before sending a message and avoid this problem.

    0 讨论(0)
  • 2020-12-05 09:58

    Check the latest manuals: http://developer.chrome.com/extensions/messaging.html

    Note: If multiple pages are listening for onMessage events, only the first to call sendResponse() for a particular event will succeed in sending the response. All other responses to that event will be ignored.

    Close your tabs, leave only one page, and check. In my case this was the issue.

    0 讨论(0)
提交回复
热议问题