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

0 votes
Hello,

Facing the above mentioned error

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

This error only shows in Chrome browser.

How can I resolve it?

Thanks in advanced!
Mar 30 in Laravel by kartik
• 10,990 points
1,289 views

1 answer to this question.

0 votes

Hii,

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

{
  "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"
  ]
}

Thank you!!

answered Mar 30 by Niroj
• 22,110 points

Related Questions In Laravel

0 votes
1 answer

Error:My Routes are Returning a 404 in Laravel?

Hii @kartik Routes Use them to define specific routes ...READ MORE

answered Mar 30 in Laravel by Niroj
• 22,110 points
145 views
0 votes
1 answer

How to solve expected response code 220 but got code “”, with message “” in Laravel?

Hii @kartik, if you are using Swift Mailer: ...READ MORE

answered Mar 31 in Laravel by Niroj
• 22,110 points
727 views
0 votes
1 answer

How Can I Set the Default Value of a Timestamp Column to the Current Timestamp with Laravel Migrations?

Hello, To create both of the created_at and updated_at columns: $t->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP')); $t->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP on update ...READ MORE

answered Apr 2 in Laravel by Niroj
• 22,110 points
298 views
0 votes
1 answer

Error:Class '\App\User' not found in Laravel when changing the namespace in Laravel?

Hello @kartik Go to config/auth.php and change App\User:class ...READ MORE

answered Apr 3 in Laravel by Niroj
• 22,110 points
382 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,110 points
417 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,110 points
62 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,110 points
64 views
0 votes
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,110 points
139 views
0 votes
1 answer

What are the important directories used in a common Laravel application

Hey @Kartik. Directories used in a common Laravel ...READ MORE

answered Mar 17 in Laravel by Niroj
• 22,110 points
33 views
0 votes
1 answer

Getting the query builder to output its raw SQL query as a String?

Hello, DB::QueryLog() only work after you execute the query $builder->get(). ...READ MORE

answered Mar 30 in Laravel by Niroj
• 22,110 points
30 views