【问题标题】:Error in code of extension for ChromeChrome 的扩展代码错误
【发布时间】:2018-04-05 01:16:21
【问题描述】:

你能帮我做这个练习吗?

如何在谷歌搜索输入的扩展输入中播放键入的值? 这是chrome的扩展,我又犯了一个错误:

错误: 拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:“script-src 'self' 'unsafe-eval' 'self'”。启用内联执行需要“unsafe-inline”关键字、哈希(“sha256-...”)或随机数(“nonce-...”)。

$(function(){
	$('#buttonSearch').click(function(){
		$('#lst-ib').text($('#name').val());
	})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
	<head>
		<title>Hello</title>
	    <!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> Not Work-->
		<script src="jquery-3.3.1.min.js"></script>
		<script src="popup.js"></script>
		<link rel="stylesheet" type="text/css" href="styles.css">
		
	</head>
	<body>
		<h1 id="greet">Hi</h1>
		<input type="text" id="name"/>   		
		<input type="button" value="escreve" id="buttonSearch" onClick="" />
	</body>
</html>

清单.json

{
  "manifest_version": 2,
  "name": "Hello World",
  "version": "1.0",
  "description": "Tsste.",
  "icons": {
    "16": "icon/sound.png"
  },
  "browser_action": {
	"default_icon": "icon/sound.png",
    "default_popup": "popup.html"
  },
  "permissions":[
    "storage"
  ],

  "content_security_policy": "script-src 'self' 'unsafe-eval' object-src 'self'"
}

我尝试了几种在互联网上传播的方法,但都没有成功。

谢谢

【问题讨论】:

  • 这个错误没有告诉你具体该怎么做吗? Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
  • 是的,但是我该怎么做呢?

标签: javascript jquery html google-chrome


【解决方案1】:

这个怎么样

[之前]

<input type="button" value="escreve" id="buttonSearch" onClick="" />

[之后]

<input type="button" value="escreve" id="buttonSearch"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    相关资源
    最近更新 更多