I'm trying to send a message to the content script running on the page in the active tab. This works fine for any normal page. However, when I try to do this for pages starting with chrome://
in the URL I get an error:
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
This is the code I'm trying to run:
// popup.js
window.addEventListener('load', (event) => {
// In case the next line yields chrome://new-tab-page
// or chrome://extensions for example
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
// Request data from app
chrome.tabs.sendMessage(tabs[0].id, "siteData", function(response) {
// error!
// Log app's response
}
}
}
//content script (even though it doesn't reach the content script)
// Site Data request
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request === "siteData") {
sendResponse({siteList: siteList, site: site, hostname: hostname});
}
}
);
Is it possible at all to establish a connection with a content script on an internal chrome page? Does the internal page even execute the content script?
Thank you
Edit: This Can you access chrome:// pages from an extension? answered my question.