Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

6,606 views
Skip to first unread message

sykes developer

unread,
Sep 6, 2022, 7:10:17 AM9/6/22
to Chromium Extensions
Hi Team,

while working on migration from MV2 to MV3, the communication message is sent from background-sctipt.js to content-script.js. I'm getting an error message when I'm checking in developer mode with the unpacked version locally. 

-----------background-script.js----------

function sendMessageToTabs(message) {
    chrome.tabs.query({}, (t) => {
        for (let x = 0; x < t.length; x++) {
            chrome.tabs.sendMessage(t[x].id, message);
        }
    })
}

----------content-sctipt.js--------------------
chrome.runtime.onMessage.addListener((data, sender, sendResponse) => {
    if (data && data.action) {
        switch (data.action) {
            case 'TABS':
                //log.debug('TABS...', data.response.tabs);
                window.postMessage(data, location.origin);
                break;
            case 'MICROTASK':
                //log.debug('MICROTASK...', data.response.microtask);
                window.postMessage(data, location.origin);
                break;
        }
    }
});


Kindly assist me to resolve this issue.

Thanks.

wOxxOm

unread,
Sep 6, 2022, 9:25:58 AM9/6/22
to Chromium Extensions, extensiondeveloper
You need to reload the tabs after reloading the extension or reinject content scripts.

sykes developer

unread,
Sep 7, 2022, 7:59:38 AM9/7/22
to wOxxOm, Chromium Extensions
Hi Woxxom,

I tried to inject a content script after I loaded the extension. but still i have the issue.
Could you assist me further.

Thanks.

sykes developer

unread,
Sep 7, 2022, 10:24:39 AM9/7/22
to wOxxOm, Chromium Extensions
hi Woxxom,

I tried to inject a content script after I loaded the extension. but still i have the issues.

1. Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
 
2. Unchecked runtime.lastError: The message port closed before a response was received.

Could you assist me further.

Thanks.

wOxxOm

unread,
Sep 7, 2022, 10:35:58 AM9/7/22
to Chromium Extensions, extensiondeveloper, Chromium Extensions, wOxxOm
Since I don't see your full code I can only make some guesses. If you used that example, you're reinjecting into the same URLs where your normal `content_scripts` runs, but then you're sending messages to all tabs including those that can't run content scripts like the start (newtab) page. You also need to wait for the injection to complete before sending messages.
Reply all
Reply to author
Forward
0 new messages