javascript - 验证安装 chrome 扩展程序时出错

标签 javascript html google-chrome google-chrome-extension

我收到错误“未捕获的 Chrome 网上应用店安装只能通过用户手势启动。”

使用此代码:

<!doctype html>
<html lang="fr">
    <head>
      <meta charset="utf-8">
      <title>Titre de la page</title>
      <link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/ajhifddimkapgcifgcodmmfdlknahffk">
      <script type="text/javascript">
        chrome.webstore.install();
      </script>
    </head>
    <body>
      test Chrome
    </body>
</html>

我不明白为什么我遵循谷歌教程:https://developer.chrome.com/webstore/inline_installation .

有人有想法吗?

谢谢。

最佳答案

来自文档(我将重要部分用斜体表示):

Triggering inline installation

To actually begin inline installation, the chrome.webstore.install(url, successCallback, failureCallback) function must be called. This function can only be called in response to a user gesture, for example within a click event handler; an exception will be thrown if it is not.

您不能只将 install() 调用放入脚本标记中并让它自动运行。

关于javascript - 验证安装 chrome 扩展程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46302468/

相关文章:

javascript - 不可枚举的属性出现在 Chrome 的 for...in 循环中

html - 背景封面最小尺寸和居中

Javascript __proto__、对象和函数

html - 如何使 iframe 居中?

css - 我怎样才能解决对 Bootstrap 3 的表单控制类的需求?

javascript - 创建 CSV 并使用 JS 打开,在 IE、Chrome 中不起作用

javascript - 使 CSS FlexBox 采用固定列宽

php - 仅加载图像一次,然后复制到多个位置?

Javascript 函数没有正确接收参数

javascript - 如何让一个容器填充另一个容器留下的空间?