1

I saw all the stackoverflow related answers about similar problem that I have. But none of them solve my problem

I have this:

manifest.json

{
   "background": {
      "page": "background.html" 
   },
   "content_scripts": [
    {
      "matches": ["http://*/*","https://*/*"],       
      "js": ["contentscript.js"],
      "run_at": "document_end",
      "all_frames": true
    }
   ],
   "web_accessible_resources": [
    "script_inpage.js"
   ],
   "browser_action": {
      "default_icon": "icon19.png",
      "default_popup": "popup.html",
      "default_title": "Player"
   },
   "content_security_policy": "script-src 'self'; media-src *; object-src 'self'",
   "description": "blah.",
   "icons": {
      "128": "icon128.png",
      "16": "icon16.png",
      "32": "icon32.png",
      "48": "icon48.png"
   },

   "manifest_version": 2,
   "minimum_chrome_version": "18",
   "name": "Player",
   "permissions": [ 
        "unlimitedStorage",
        "http://*/",
        "tabs"
   ],
   "update_url": "http://clients2.google.com/service/update2/crx",
   "version": "2.6"
}

background.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="background.js"></script>

</head>
<body>
    <audio src="" id="mplayer"></audio>
</body>
</html>

background.js

function playMusicFile() {

    console.log("playMusicPlayer() from background.js");

    var id="";
    chrome.tabs.getSelected(null, function(tab) {
          id=tab.id; 
          console.log(tab.id);
          var port = chrome.tabs.connect(id);
          port.postMessage({text: "post from plugin",name:"playermsg"});
    });  

    document.getElementById("mplayer").play()
}

contentscript.js

var portRec = chrome.extension.connect();
chrome.extension.onConnect.addListener(function(port) {
  portRec.onMessage.addListener(function(msg) {
    alert(msg["text"]+"  "+msg["name"]);
    portRec.postMessage({text: "hello"});
  });
});

and i keep getting this error after i see the log print:

Port error: Could not establish connection. Receiving end does not exist. miscellaneous_bindings:235 chromeHidden.Port.dispatchOnDisconnect

Falko
  • 17,076
  • 13
  • 60
  • 105
user63898
  • 29,839
  • 85
  • 272
  • 514
  • 1
    I just wrote an answer on a similar question here: http://stackoverflow.com/a/13367264/612202 Maybe this helps you? – dan-lee Nov 13 '12 at 19:30

0 Answers0