2013-08-27 25 views
0

我的清单:Chrome扩展:端口:无法建立连接

{ 
    "name":"name", 
    "version":"0.1", 
    "manifest_version":2, 
    "description":"name app", 
    "background":{ 
     "scripts":[ 
      "scripts/modernizr.min.js", 
      "scripts/background.js" 
      ], 
     "persistent": false 
    }, 
    "content_scripts": [ 
     { 
     "matches": ["https://*/*", "http://*/*"], 
     "js": ["scripts/content.js"], 
     "run_at": "document_end" 
     } 
    ], 
    "permissions":[ 
     "contextMenus", 
     "tabs", 
     "http://*/*", 
     "https://*/*" 
     ], 
    "icons":{ 
     "16":"images/icon_16.png", 
     "128":"images/icon_128.png" 
    } 
} 

Background.js有一个调用的函数:

chrome.contextMenus.onClicked.addListener(function(info, tab) 
     { 
... stuff ... 
    chrome.tabs.sendMessage(tab.id, { action: "showLibraryUI", library: library }, function(response){}); 

    }); 

在content.js我有监听功能,但它从未被称为:

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) 
    { 
...stuff... 
}); 

在_generated_background_page.html为扩展我看到这一点:

端口:无法建立连接。接收结束不存在。 lastError:29 集lastError:29个 dispatchOnDisconnect miscellaneous_bindings:259

我找不到在这里因此其他职位清单> 2.0的解决方案。

+0

代码看起来没问题。你确定代码的chrome.runtime.onMessage位运行吗? –

+0

background.js中的所有内容都正常运行。在background.js中我不确定是否chrome.tabs.sendMessage(tab.id,{action:“showLibraryUI”,library:library}正在工作,因为content.js中的监听器没有被调用。 – Lebowski156

+0

@RobW我找到了解决方案:) – Lebowski156

回答

0

我找到了解决我的问题的方法。我的content.js中有一个语法错误。这导致content.js没有运行,并且监听器不在场。

相关问题