且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Chrome显示错误为:由于内容安全策略拒绝执行内联脚本

更新时间:2021-07-04 03:24:30

Chrome扩展程序CSP文档

From the Chrome extension CSP docs:


内联JavaScript将不会执行。此限制禁止内联< script> 块和内联事件处理程序(例如< button onclick =...> )。

Inline JavaScript will not be executed. This restriction bans both inline <script> blocks and inline event handlers (e.g. <button onclick="...">).

不能在您的扩展HTML中包含内嵌脚本,如:

You cannot have inline scripts in your extension HTML like:

<script>alert("I'm an inline script!");</script>

<button onclick="alert('I am an inline script, too!')">

相反,您必须将脚本放入单独的文件中:

Rather, you must place your script into a separate file:

<script src="somescript.js"></script>