I'm developing an extension in Chrome, and there's a problem. In my inject.js
, I make a request like:
chrome.extension.sendRequest({command:'skip'},callback)
and in my `background.js I simply add a request Listener like:
chrome.extension.onrequest.addListener(function(req,sender,res){console.log("procession"})
But there's an error:
Port error: Could not establish connection. Receiving end does not exist
It seems a bug in chrome? PS:
part of my manifest.json
"background": { "scripts": ["background.js"] }, "content_scripts": [ { "matches": ["< all_urls >"], "js": ["inject.js"] } ],
I'm in Chromium 17, and I tried reloading the extension, reopening the browser... nothing happened
some one get some ideas?
Receiving End Does Not Exist Error Happening? This error usually happens due to a problem with a specific Chrome extension inside your main document. The program cannot establish a connection, and many web developers are usually faced with this error while working on Chrome.
The "Could not establish connection." occurs after a page load when Web Scraper tries to extract data from the specific URL and the page hasn't loaded. This can be related to loosing network connection or being blocked by the site in their firewall. If the error happens in browser extension, the page will be skipped.
The background script should be viewed as "running in the background of the Chrome browser". Your desired effect (running a script for every page) is actually a task for content scripts. To learn more, read https://developer.chrome.com/extensions/overview.html#arch. Follow this answer to receive notifications.
When sending a message to the content script, we need to specify which tab to send it to. Therefore, we need to retrieve the active tab information first, and then use tabs. sendMessage . To use the tabs API and to have access to the active tab, you need to add tabs and activeTab under permissions in your manifest.
This isn't always the cause, but if you have an error in your background.js
, you should check this link:
Inspect views: _generated_background_page.html
in the Extensions page, which will show you any JavaScript errors.
This was preventing my connections from getting established.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With