Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法通过Chrome扩展弹出窗口创建JS弹出窗口_Javascript_Google Chrome_Google Chrome Extension_Popup - Fatal编程技术网

Javascript 无法通过Chrome扩展弹出窗口创建JS弹出窗口

Javascript 无法通过Chrome扩展弹出窗口创建JS弹出窗口,javascript,google-chrome,google-chrome-extension,popup,Javascript,Google Chrome,Google Chrome Extension,Popup,我正在尝试创建我的第一个Chrome扩展,但我在让我的JS正常工作方面遇到了问题。 我想做的就是,当我点击“Activer”时,它会显示一个弹出窗口,上面写着“hello” 这是我在github中找到的一段代码,我试图对其进行调整。 当我检查扩展时,会出现如下错误: Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "http://stackoverflow.co

我正在尝试创建我的第一个Chrome扩展,但我在让我的JS正常工作方面遇到了问题。 我想做的就是,当我点击“Activer”时,它会显示一个弹出窗口,上面写着“hello”

这是我在github中找到的一段代码,我试图对其进行调整。 当我检查扩展时,会出现如下错误:

Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "http://stackoverflow.com/questions/ask". Extension manifest must request permission to access this host.
at HTMLDivElement.hello (chrome-extension://clolnlfhhjonbfknjgebnmnfanpmcono/popup.js:4:15)
这是我的manifest.json

{
"name": "e-kootsa",
"version": "1.0",
"manifest_version": 2,
"description": "Ce plugin vous permet d'écouter le texte d'une page",
"browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
},
"options_page": "options.html"
}
这是我的popup.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<style type="text/css">
body{
    margin: 0px;
    padding: 0px;
    font-family: Arial, Sans-serif;
    font-size: 20px;
    width: 200px;
}
.selection{
    text-align: center;
    margin-bottom: 5px;
}
.global{
    padding-top: 5px;
}

a{
    text-decoration: none;
    color: #000;
}
</style>
</head>
<body>
<div class="global">
    <div class="selection"><a href="options.html" target="_blank">Paramètres</a></div>
    <hr />
    <div class="selection" id="clickme"><a href="#">Activer</a></div>
    <hr />
    <div class="selection"><a href="about.html" target="_blank">À propos</a>        </div>
</div>
<script type="text/javascript" src="popup.js"></script>
</body>
</html>
这是我的alert.js

alert('hello ' + document.location.href);
console.log('Tryhard');
我知道我一定犯了一些错误,但我仍然很难理解如何使事情顺利进行


提前谢谢你

有关更保守的解决方案,请参见

======

它与活动选项卡一起工作,因此您需要在清单中为希望其工作的每个可能URL添加权限=所有URL:
“权限”:[“”]
。因此,您的清单将如下所示:

...
"browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
},
"permissions": ["<all_urls>"],
"options_page": "options.html"
。。。
“浏览器操作”:{
“默认图标”:“icon.png”,
“默认弹出窗口”:“popup.html”
},
“权限”:[“”],
“选项页面”:“options.html”
只是补充说它应该可以正常工作。

是有效的,但没有达到最佳效果

如果您正在使用这样的活动选项卡,那么您不需要对所有内容都进行全面许可。声明
,专门用于此目的。当用户调用扩展时(例如,按下按钮),它授予当前选项卡的权限


如果你不知道的话,请看我的答案,了解一个更保守的解决方案。谢谢,不确定我是否知道:)该死的,我爱这个社区,它现在就像一个魅力!
...
"browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
},
"permissions": ["<all_urls>"],
"options_page": "options.html"
"permissions": ["activeTab"],