Chrome 内联插件安装于 window.confirm

Chrome inline plugin install on window.confirm

我可以使用 window.confirm to trigger Chrome extension/app 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.

来自文档:必须调用 chrome.webstore.install 以响应 用户手势 。我可以使用浏览器确认弹出窗口来完成吗?

 if (confirm("Press a button!") == true) {
   var app =
     'https://chrome.google.com/webstore/detail/omcplobmjajgpmpcdnbdiblienjeljan';
   chrome.webstore.install(app, function() {
     console.log('Success');
   }, function(errorMessage) {
     console.log('Error: ' + errorMessage)
   });
 }
<link 
  rel="chrome-webstore-item" 
  href="https://chrome.google.com/webstore/detail/omcplobmjajgpmpcdnbdiblienjeljan"
>

我无法自己测试,因为我没有经过验证的域

首先是什么触发了确认?我猜这是重要的部分。如果你事先没有用户交互就弹出确认,我怀疑它会起作用。

据我了解用户手势要求,这意味着 "in the context of an event listener triggered by a user gesture"。来自模式的响应不是这样的听众。 注:这是猜测,我没有测试过。

Since inline installation has to be triggered via a user gesture (for example, a mouse click) it is therefore suggested that you tie the action to a clickable user interface element such as a button. It is suggested that you use the same button label as the Chrome Web Store itself (in English, this is "Add to Chrome").

此处的文档引用了 DOM 个元素,即使它不是明确的。

事实上,如果在显示对话框之前没有用户手势它确实可以工作,我认为这是一个错误,因为用户无法避免与 confirm.[=12= 交互]