Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue?

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.

like image 395
Triumf Maqedonci Avatar asked Jan 10 '19 10:01

Triumf Maqedonci


People also ask

How fix unchecked runtime Lasterror The message port closed before a response was received?

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.

How do I fix unchecked runtime?

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.


2 Answers

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

like image 172
MirekH Avatar answered Oct 07 '22 06:10

MirekH


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]

like image 20
Ofek Shilon Avatar answered Oct 07 '22 06:10

Ofek Shilon