Skip to content
Advertisement

Google Chrome extensions simple message passing error

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:

JavaScript

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

JavaScript

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

JavaScript

Any thoughts?

Advertisement

Answer

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

JavaScript

background.js

JavaScript

popup.html

JavaScript

popup.js

JavaScript

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

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement