Copying the sample code and filling in the gaps with the manifest and pop-up structure led to the creation of a fully working extension without errors. Not sure why you get an error message. Try my code and see if you can get rid of the error.
Tips
- Alerts in the pop-up window will cause a warning to appear on the screen, and then both will be closed before you can see them. It is probably best to simply log into the console for testing as follows.
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 msg"}, function(b){ console.log('this is popups callback func ' + b.backgroundMsg); });
Screenshot example
Pressing an extension button with a browser open on exampley.com

Popup Extension Console Log

Here are the zip files that I used http://mikegrace.s3.amazonaws.com/stackoverflow/simple-popup.zip
source share