【发布时间】:2022-11-19 22:19:17
【问题描述】:
我希望我的扩展重新加载我当前所在的页面
所以我的扩展程序中有一个按钮,我尝试了这个:
<a href="javascript:; " onclick="window.location.reload();">reload</a>
它显示如下错误:
Refused to run the JavaScript URL because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present.
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present.
但后来我尝试改用函数,我使用了以下 javascript 代码:
document.getElementById('btnReload').onclick = function(){
window.location.reload();
console.log("reload successfull");
}
我发现,它实际上是在重新加载扩展程序而不是页面(例如;如果我现在单击重新加载 - 我希望它重新加载 stackoverflow.com)...我该怎么做?我正在使用 vanilla javascript、html5 和 manifest v3
【问题讨论】:
标签: javascript html google-chrome-extension manifest reload