Help me, please! I get error "Unchecked runtime.lastError: Cannot access contents of url "". Extension manifest must request permission to access this host." and "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist." in manifest 3.
Listener from content script
chrome.runtime.onMessage.addListener(
function(req, sender, sendResponse) {
if(req.msg === "analysis background") {
let obj = parse();
sendResponse(obj);
}
return true;
}
);
);
manifest.json
{
"manifest_version": 3,
"name": "extensionParser",
"version": "1.0.0",
"action": {
"default_popup": "popups/popup.html"
},
"background": {
"service_worker": "background.js"
},
"permissions": ["tabs", "scripting",
"http://localhost/site_for_parsing"]
}
Code from background file
const siteUrl = "http://localhost/site_for_parsing";
chrome.runtime.onConnect.addListener(port => {
port.onMessage.addListener(msg => {
if(msg.message === 'analysis') {
chrome.tabs.create({active: false, url: siteUrl}, tab => {
chrome.scripting.executeScript({
target: {tabId:tab.id},
files: ['dist/parser.js']
}, (results) => {
chrome.tabs.sendMessage(tab.id, {msg: "analysis background"}, res => {
port.postMessage(res)
chrome.tabs.remove(tab.id)
})
})
});
}
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…