我正在尝试制作一个chrome扩展,它覆盖新的选项卡页面,然后后台服务对该页面进行更改。因此,在我的清单中,我有(除其他外):
"manifest_version": 3,
"chrome_url_overrides": {
"newtab": "newtab.html"
},
"permissions": [ "scripting", "activeTab" ... and many many others!
这很好,因为当我添加一个新的选项卡时,我确实看到了我放在自己的自定义“newtab.html”中的文件的内容。
在清单中,我还放了。。。
"host_permissions": [
"<all_urls>",
"chrome://newtab/"
],
…然后在我的后台服务中,作为一个测试,我输入:
chrome.scripting.executeScript({
target: { tabId: tabId },
func: () => {
const h1 = document.createElement('h1');
h1.textContent = 'Hello';
document.body.appendChild(h1);}
});
但是当这个代码运行时,我得到:
Uncaught (in promise) Error: Cannot access contents of url "chrome-extension://mhjkkbnnfoaeadgpnoheabgocjfhgkli/newtab.html". Extension manifest must request permission to access this host.
我已经广泛搜索了答案,并添加了许多不同的权限和host_permissions,但到目前为止没有任何效果。