【发布时间】:2018-07-07 16:10:25
【问题描述】:
根据permissions documentation,如果我们有activeTab权限,我们不需要指定基于URL的权限
以下任何 URL 都匹配所有主机:
http://*/* https://*/* *://*/* <all_urls>请注意,您可以避免声明所有主机权限 使用 activeTab 权限。
但这只能工作一次,第二次出现错误(扩展 UI 在我们第二次尝试时打开),如果我们通过单击扩展图标再次启动弹出窗口,它工作正常。
Unchecked runtime.lastError while running tabs.executeScript:
Cannot access contents of the page.
Extension manifest must request permission to access the respective host.
以下是详细信息
manifest.json
{
"manifest_version": 2,
"name": "Getting started example",
"description": "This is hello world example",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"activeTab"
]
}
popup.html
<html>
<head>
<title>Getting Started Extension's Popup</title>
<script src="popup.js"></script>
</head>
<body>
<div>Hello World!</div>
<input type="button" id="refreshPage" value="Refresh Page"/>
</body>
</html>
popup.js
document.addEventListener('DOMContentLoaded', function() {
function refreshPage() {
chrome.tabs.executeScript(null, {
code: 'window.location.reload(true)'
}, function(){
console.log("Page refershed");
});
}
document.getElementById("refreshPage").addEventListener("click", refreshPage);
});
如果我们添加"*://localhost/*"(这适用于本地主机),还有另一种方法可以为所有主机指定*://*/*(不确定这是否正确且安全),刷新按钮可以多次工作而无需重新启动弹出UI . activeTab 与基于 URL 的权限之间是否存在差异,并且由于特定原因,建议使用任何特定方式而不是另一种方式?
【问题讨论】:
-
在 Chromium 上提出了一个错误。 Refer bug # 806633 了解更多详情。