I'm developing a Google Chrome extension, which produces an error I can't fix.
My manifest.json looks like this:
{
"name": "my extension",
"version": "1.0",
"background_page": "background.html",
"permissions": [
"tabs",
"<all_urls>"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"],
"all_frames": true
}
]
}
background.html tries to talk with content.js:
<script>
chrome.tabs.onUpdated.addListener
(
function(tabId, changeInfo)
{
chrome.tabs.sendRequest(tabId, {action : 'getMyValue'}, function(output) {
console.log(output);
});
}
);
</script>
Finally, content.js:
chrome.extension.onRequest.addListener(function(request, sender, callback)
{
if (request.action == 'getMyValue')
{
callback('test');
}
});
Developer Tools console prints: "Port error: Could not establish connection. Receiving end does not exist." in "miscellaneous_bindings" on line 232.
Any ideas?
I'm developing a Google Chrome extension, which produces an error I can't fix.
My manifest.json looks like this:
{
"name": "my extension",
"version": "1.0",
"background_page": "background.html",
"permissions": [
"tabs",
"<all_urls>"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"],
"all_frames": true
}
]
}
background.html tries to talk with content.js:
<script>
chrome.tabs.onUpdated.addListener
(
function(tabId, changeInfo)
{
chrome.tabs.sendRequest(tabId, {action : 'getMyValue'}, function(output) {
console.log(output);
});
}
);
</script>
Finally, content.js:
chrome.extension.onRequest.addListener(function(request, sender, callback)
{
if (request.action == 'getMyValue')
{
callback('test');
}
});
Developer Tools console prints: "Port error: Could not establish connection. Receiving end does not exist." in "miscellaneous_bindings" on line 232.
Any ideas?
Share Improve this question edited Jul 4, 2012 at 15:54 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Jul 4, 2012 at 13:12 TorbenLTorbenL 1,3191 gold badge12 silver badges15 bronze badges 7-
1
Can't reproduce. Any conflicting extensions? Also, are you aware that
onUpdated
is fired twice for each pageview? – Rob W Commented Jul 4, 2012 at 13:34 - How can i figure out if there are any conflicting extensions? Is it possible to debug extensions in incognito mode? – TorbenL Commented Jul 4, 2012 at 14:50
-
1
A1. Either start Chrome using a new profile (
chrome --user-data-dir=%tmp%\%random%
in Windows,chromium-browser --user-data-dir=/tmp/$RANDOM
under Linux), or disable all extensions, and add them one-by-one. A2. See this answer. – Rob W Commented Jul 4, 2012 at 14:56 - @RobW same error in incognito mode (no other extensions activated) :( – TorbenL Commented Jul 4, 2012 at 15:08
- @RobW New chrome profile prints "Port error: Could not establish connection. Receiving end does not exist.", too. function: chromeHidden.Port.dispatchOnDisconnect – TorbenL Commented Jul 4, 2012 at 15:12
1 Answer
Reset to default 4chrome.tabs.onUpdated
runs when a tab updates. Dev tools, chrome (extension) pages etc. are also included. To get rid of the error, you have to filter the URLs you cannot access.
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) {
// Example: allow http:, https: and file:
if (changeInfo.status === 'plete' &&
/^(https?|file):/.test(changeInfo.url)) {
chrome.tabs.sendRequest(tabId, {action: 'getMyValue'}, function(output) {
console.log(output);
});
}
});