【问题标题】:how to reload a page with an extension? (manifest v3) [duplicate]如何重新加载带有扩展名的页面? (清单 v3)[重复]
【发布时间】: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


    【解决方案1】:

    您可以使用 chrome 选项卡获取当前选项卡 ID 并执行脚本。

    请参考https://developer.chrome.com/docs/extensions/reference/tabs/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      • 2019-07-24
      • 1970-01-01
      • 2019-12-20
      • 1970-01-01
      相关资源
      最近更新 更多