Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8399581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:20:53+00:00 2026-06-09T21:20:53+00:00

I am trying to pass a message between my popup to a background page

  • 0

I am trying to pass a message between my popup to a background page using the one message interface (I’m using code similar to the one in Google’s example for this).

popup:

chrome.extension.sendMessage( {msg: "this is popup's msg"}, function(b){
    alert('this is popups callback func' +b.backgroundMsg);
});

and this is how I listen (and reply) in background.js:

chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
    sendResponse({backgroundMsg: "this is background msg"});
});

Now when I inspect everything in the console the messages are exchanged ok but I get the following error:

Error in event handler for 'undefined': Cannot call method 'disconnect' of null TypeError: Cannot call method 'disconnect' of null
    at chromeHidden.Port.sendMessageImpl (miscellaneous_bindings:285:14)
    at chrome.Event.dispatch (event_bindings:237:41)
    at Object.chromeHidden.Port.dispatchOnMessage (miscellaneous_bindings:250:22)

Any thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:20:54+00:00Added an answer on June 9, 2026 at 9:20 pm

    Copying your code example and filling in the blanks with the manifest and popup structure resulted in a fully working extension without errors. Not sure why you are getting the error that you shared. Try my code and see if you can get rid of the error.

    Tips

    • Alerts in the popup will result in the alert flashing on the screen and then both will close before you can see them. It is probably better to just log to the console for testing like this.

    Example

    manifest.json

    {
        "name": "Stackoverflow Message Passing Example",
        "manifest_version": 2,
        "version": "0.1",
        "description": "Simple popup with message passing for Stackoverflow question",
        "browser_action": {
            "default_popup": "popup.html"
        },
        "background": {
            "scripts": ["background.js"]
        }
    }
    

    background.js

    chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
        sendResponse({backgroundMsg: "this is background msg"});
    });
    

    popup.html

    <html>
        <head>
            <script src="popup.js"></script>
            <style type="text/css" media="screen">
                body { width: 100px; height: 100px; }
            </style>
        </head>
        <body>
            <p>Check the console</p>
        </body>
    </html>
    

    popup.js

    chrome.runtime.sendMessage( {msg: "this is popup's msg"}, function(b){
        console.log('this is popups callback func ' + b.backgroundMsg);
    });
    

    Running Example Screenshots

    Clicking extension button with browser window opened to exampley.com

    Clicking extension button with browser window opened to exampley.com

    Console log of extension popup

    Console log of extension popup

    Here is a zip of the files I used http://mikegrace.s3.amazonaws.com/stackoverflow/simple-popup.zip

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use this jQuery postMessage plugin to pass messages between a couple
I'm trying to pass messages between 2 threads using a queue, but I haven't
I am trying to pass messages between several classes that communicate through interface. However,
I am trying some code like this //A.hpp class A{ public: A() {} virtual
I am trying to display an lengthy message in Default AlertDialog with following code.
client.on('message', function(obj){}); This works fine, but I am trying to avoid nesting, so I
I am trying to pass a dataString to to an ajax call using JQuery.
I'm using rails version 3.2.6 and I'm trying to pass a Javascript variable to
I'm trying to pass an error message from a grails controller to a grails
I am trying to pass a function pointer using boost::bind. void Class::ThreadFunction(Type(*callbackFunc)(message_type::ptr&)) { }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.