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 Chrome browser.
Your answer The solution is to return true in background message listener. Here is simple example of background. js. It responses to any message from popup.
To solve this issue, first toggle off all the installed extensions in your chrome browser. Then reload the page and check if the issue is resolved. You should not get any error this time. Now turn on the extensions one by one and keep checking the page by reloading after enabling an extension.
I disabled all installed extensions in Chrome - works for me. I have now clear console without errors.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With