我想用 Chrome 扩展程序抓取维基百科页面。 但是当我使用 chrome.tabs.executeScript 时出现错误:“扩展清单必须请求访问此主机的权限”
我不明白,因为我认为有足够的权限。 如果有人可以帮助我,我将不胜感激:)
manifest.json
partially success
(是的,我正在尝试获得很多许可^^')
popup.js
{
"manifest_version": 2,
"name": "scrapTest",
"description": "Baked goods list",
"version": "1.0",
"permissions": [
"webNavigation",
"tabs",
"background",
"<all_urls>",
"webRequest",
"webRequestBlocking",
"storage",
"*://*.wikipedia.com/*",
"https://en.wikipedia.org/wiki/List_of_baked_goods",
"http://*/*",
"https://*/*",
"*://*/*"
],
"background": {
"scripts" : ["js/background.js"],
"persistent": true
},
"browser_action": {
"default_popup": "popup.html"
}
}
scrappingTest.js
var wikiTabId = null;
chrome.tabs.query({windowId: chrome.windows.WINDOW_ID_CURRENT}, (tabs) => {
for (let i = 0; i < tabs.length; i++) {
if (tabs[i].url.includes("en.wikipedia.org/wiki/List_of_baked_goods")) {
wikiTabId = tabs[i].id;
}
}
});
chrome.tabs.executeScript(wikiTabId, {"file": "scrappingTest.js"}, function () { // Execute your code
console.log("Script Executed... "); // Notification on Completion
});
popup.html
JSON.stringify([...document.querySelectorAll('ul > li > a')].map(r => r.textContent))
错误
<块引用>未检查的 runtime.lastError:无法访问 url 的内容 “chrome-extension://gjppkjbdaenhjcggdeglnfldgmfgdonp/popup.html”。 扩展清单必须请求访问此主机的权限。