470

I'm using VueJS and Laravel for my project. This issue started to show lately and it shows even in the old git branches.

This error only shows in the Chrome browser.

3UMF
  • 5,162
  • 2
  • 15
  • 26
  • 19
    Do you have any ad blocker ? – Maelig Jan 10 '19 at 10:36
  • 1
    Check my answer to this other request: https://stackoverflow.com/questions/53919591/chrome-angular-unchecked-runtime-lasterror-the-message-port-closed-before-a-res – Dolfiz Jan 10 '19 at 11:38
  • 19
    Thanks guys, the problem was the extension "Video Downloader professional". – 3UMF Jan 10 '19 at 14:05
  • 7
    **Moderator Note:** We don't need new answers listing every extension you've found to cause this problem. A single answer saying that the problem can be caused by extensions and recommending to disable them is sufficient. Answers that do nothing more than name an extension have been and will continue to be deleted. – Cody Gray - on strike Oct 24 '21 at 06:40
  • 5
    https://stackoverflow.com/questions/59914490/how-to-handle-unchecked-runtime-lasterror-the-message-port-closed-before-a-res perhaps the answer here is more beneficial than simply 'disable x extension' – bongoSLAP Jan 03 '22 at 00:43
  • 1
    VeePN extension (https://chrome.google.com/webstore/detail/free-vpn-for-chrome-vpn-p/majdfhpaihoncoakbjgbdhglocklcgno) generates this error in Chrome too. It's the price for letting extensions mess up with core! – sasho Apr 23 '22 at 11:51

18 Answers18

498

I disabled all installed extensions in Chrome - works for me. I have now clear console without errors.

MirekH
  • 5,236
  • 1
  • 13
  • 5
265

In case you're an extension developer who googled your way here trying to stop causing this error:

The issue isn't CORB (as another answer here states) as blocked CORs manifest as warnings like -

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://www.example.com/example.html with MIME type text/html. See https://www.chromestatus.com/feature/5629709824032768 for more details.

The issue is most likely a mishandled async response to runtime.sendMessage. As MDN says:

To send an asynchronous response, there are two options:

  • return true from the event listener. This keeps the sendResponse function valid after the listener returns, so you can call it later.
  • return a Promise from the event listener, and resolve when you have the response (or reject it in case of an error).

When you send an async response but fail to use either of these mechanisms, the supplied sendResponse argument to sendMessage goes out of scope and the result is exactly as the error message says: your message port (the message-passing apparatus) is closed before the response was received.

Webextension-polyfill authors have already written about it in June 2018.

So bottom line, if you see your extension causing these errors - inspect closely all your onMessage listeners. Some of them probably need to start returning promises (marking them as async should be enough). [Thanks @vdegenne]

Ofek Shilon
  • 14,734
  • 5
  • 67
  • 101
  • 29
    As an heads up don't use `async/await` for your background listener callback. This is what failed for me, I removed `async` and transformed my `await` structure in a `then` structure code and now it works. – vdegenne Oct 02 '19 at 17:06
  • 2
    but... i'm not trying to send any response, nor am I expecting one! – Michael Mar 31 '20 at 03:45
  • 21
    What a great fix, thanks! All I had to do is add `return true;` at the bottom of my _chrome.runtime.onMessage.addListener()_ function and the problem was solved! I am using jQuery's `$.ajax` inside this function which is why I need this fix. – RcoderNY Jul 09 '20 at 04:45
  • 1
    @vdegenne you can use `async` for the listener, but then you can't `return true` at the end, and can't use the `sendResponse` callback. You just have to resolve **with** the actual response. – Papooch Feb 26 '21 at 12:22
  • this worked for me, but I had to return true from the callback in chrome.tabs.executeScript, which was inside a listener. – Zafar Mar 10 '21 at 21:29
  • 1
    Just calling sendResponse({}) within a (non-async) addListener callback worked for me (no need to return true, and just returning true didn't work for me) – Nicolas Trahan Oct 01 '21 at 19:07
  • 2
    @Michael In Chrome v99+ extensions, this is a bug: https://stackoverflow.com/q/71520198/2336725 – Teepeemm Apr 10 '22 at 22:04
  • @Teepeemm Curiously, I'm getting the same issue in Chrome 101 with a Manifest V2 extension. At least it should be fixed in 102. – Dai May 12 '22 at 19:51
  • Thats was very helpful I did get the same error because I was not executing the callback function in the message receiver. After adding that call everything is working perfectly. Thank you! – Hristo Petev Sep 24 '22 at 21:12
86

If you go to chrome://extensions/, you can just toggle each extension one at a time and see which one is actually triggering the issue.

Once you toggle the extension off, refresh the page where you are seeing the error and wiggle the mouse around, or click. Mouse actions are the things that are throwing errors.

So I was able to pinpoint which extension was actually causing the issue and disable it.

Aguayma
  • 955
  • 5
  • 10
61

Post is rather old and not closely related to Chrome extensions development, but let it be here.

I had same problem when responding on message in callback. The solution is to return true in background message listener.

Here is simple example of background.js. It responses to any message from popup.js.

chrome.runtime.onMessage.addListener(function(rq, sender, sendResponse) {
    // setTimeout to simulate any callback (even from storage.sync)
    setTimeout(function() {
        sendResponse({status: true});
    }, 1);
    // return true;  // uncomment this line to fix error
});

Here is popup.js, which sends message on popup. You'll get exceptions until you un-comment "return true" line in background.js file.

document.addEventListener("DOMContentLoaded", () => {
    chrome.extension.sendMessage({action: "ping"}, function(resp) {
        console.log(JSON.stringify(resp));
    });
});

manifest.json, just in case :) Pay attention on alarm permissions section!

{
  "name": "TestMessages",
  "version": "0.1.0",
  "manifest_version": 2,
  "browser_action": {
    "default_popup": "src/popup.html"
  },
  "background": {
    "scripts": ["src/background.js"],
    "persistent": false
  },
  "permissions": [
    "alarms"
  ]
}
Aleksej Vasinov
  • 2,662
  • 28
  • 29
  • It worked for me! What scenario the default `return false` would be useful? – Eduardo Reis Apr 27 '20 at 19:59
  • [Docs says](https://developer.chrome.com/extensions/runtime#event-onMessage): `This function becomes invalid when the event listener returns, unless you return true`. What means invalid? doesn't it suppose to be created every time it receives a message anyways? – Eduardo Reis Apr 27 '20 at 20:01
  • @EduardoReis, with FALSE it could be used as informer to notify about some event. – Aleksej Vasinov Apr 28 '20 at 06:21
  • Aleksej, Can you help me how to include addListener code in struts 1 web project . i use JS, JSP,HTML , FRAMES, CSS as UI stack. just wondered where exactly need to apply it. tried added below snippet in parent js file but it doesn't recognize. usually i dont have listener code in my app. chrome.runtime.onMessage.addListener(function(rq, sender, sendResponse) { setTimeout(function() { sendResponse({status: true}); }, 1); alert("Inside Background.js file"); return true; // Return true to fix the error }); – sasrra Dec 21 '21 at 09:28
  • Sorry, I don't know JSP to help you with. Did you locate listener in your JS code? – Aleksej Vasinov Dec 22 '21 at 07:18
28

To me i was using a VPN extension called Free VPN for Chrome - VPN Proxy VeePN It was causing the error after disabling it only ... the error disappeared

Zaid abu khalaf
  • 776
  • 8
  • 15
14

This error is generally caused by one of your Chrome extensions.

I recommend installing this One-Click Extension Disabler, I use it with the keyboard shortcut COMMAND (⌘) + SHIFT (⇧) + D — to quickly disable/enable all my extensions.

Once the extensions are disabled this error message should go away.

Peace! ✌️

Ahmad Awais
  • 33,440
  • 5
  • 74
  • 56
  • ctrl+shit+d - don't work in linux, and no hotkeys for this extension. https://chrome.google.com/webstore/detail/disable-extensions-tempor/lcfdefmogcogicollfebhgjiiakbjdje And tanks for this extension. – serii Feb 11 '22 at 07:33
10

Make sure you are using the correct syntax.

We should use the sendMessage() method after listening it.

Here is a simple example of contentScript.js It sendRequest to app.js.

contentScript.js

chrome.extension.sendRequest({
    title: 'giveSomeTitle', params: paramsToSend
  }, function(result) { 
    // Do Some action
});

app.js

chrome.extension.onRequest.addListener( function(message, sender, 
 sendResponse) {
  if(message.title === 'giveSomeTitle'){
    // Do some action with message.params
    sendResponse(true);
  }
});
Gopal B Shimpi
  • 129
  • 1
  • 6
  • 1
    `sendRequest` is deprecated use `sendMessage` – user889030 Aug 03 '20 at 07:33
  • Hi, Can some one help me how to include addListener code in struts 1 web project . i use JS, JSP,HTML , FRAMES, CSS as UI stack. just wondered where exactly need to apply it. tried added below snippet in parent js file but it doesn't recognize. usually i dont have listener code in my app. chrome.runtime.onMessage.addListener(function(rq, sender, sendResponse) { setTimeout(function() { sendResponse({status: true}); }, 1); alert("Inside Background.js file"); return true; // Return true to fix the error }); – sasrra Dec 21 '21 at 09:29
9

If error reason is extension use incognito Ctrl+Shift+N. In incognito mode Chrome does not have extensions.

UPD. If you need some extension in incognito mode e.g. ReduxDevTools or any other, in extension settings turn on "Allow in incognito"

airush
  • 722
  • 9
  • 19
5

For those coming here to debug this error in Chrome 73, one possibility is because Chrome 73 onwards disallows cross-origin requests in content scripts.

More reading:

  1. https://www.chromestatus.com/feature/5629709824032768
  2. https://www.chromium.org/Home/chromium-security/extension-content-script-fetches

This affects many Chrome extension authors, who now need to scramble to fix the extensions because Chrome thinks "Our data shows that most extensions will not be affected by this change."

(it has nothing to do with your app code)

UPDATE: I fixed the CORs issue but I still see this error. I suspect it is Chrome's fault here.

Jonathan Lin
  • 19,922
  • 7
  • 69
  • 65
1

In my case it was a breakpoint set in my own page source. If I removed or disabled the breakpoint then the error would clear up.

The breakpoint was in a moderately complex chunk of rendering code. Other breakpoints in different parts of the page had no such effect. I was not able to work out a simple test case that always trigger this error.

AnthonyVO
  • 3,821
  • 1
  • 36
  • 41
1
  • I faced the same error in my react project running.

That error coming from my chrome

IObit Surfing Protection
2.2.7

extensions. That extension off my error was solved.

If you face same like that error, 1st turn off your chrome ad blocker or any other extensions while running.

Thirosh Madhusha
  • 237
  • 2
  • 11
1

Late here but in my case it was Kaspersky Cloud Protection Extension. I disabled it. It worked all good.

Amax
  • 47
  • 8
1

my problem was "Youtube Playback Speed Control" chrome extension but I need that so I don't do anything:)

PouriaDiesel
  • 660
  • 8
  • 11
0

I suggest you first disable all the extensions then one by one enable them until you find the one that has caused the issue in my case Natural Reader Text to Speech was causing this error so I disabled it. nothing to do with Cross-Origin Read Blocking (CORB) unless the error mention Cross-Origin then further up the tread it is worthwhile trying that approach.

Waheed Rafiq
  • 460
  • 1
  • 6
  • 17
0

The cause of this issue is related to one of your chrome extensions, not CORS or CORB. To fix that you can turn off each and every chrome extension you installed.

wahsandaruwan
  • 587
  • 5
  • 7
0

Norton Safe Web extension for chrome is throwing this error message for me. After I disabled this extension, the error message disappeared.

0

Just cleaning site cookies worked here.

Eduardo M
  • 229
  • 5
  • 14
0

In my case i had to switch off "Adblock extension" from chrome.

Cineczeq
  • 49
  • 6
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 24 '23 at 12:41