Search code examples
javascriptgoogle-chromegoogle-chrome-extensiongoogle-chrome-appchrome-web-store

Chrome inline plugin install on window.confirm


Can I use 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.

From documentation: chrome.webstore.install must be called in response to a user gesture. Can I do it with using browser confirm popup?

 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"
>

I can't test it myself, because I have no verified domains


Solution

  • What triggers the confirm in the first place? I'm guessing that's the important part. If you pop up the confirm without user interaction beforehand, I doubt it'll work.

    As far as I understand user gesture requirements, this means "in the context of an event listener triggered by a user gesture". Response from a modal isn't such a listener. Note: this is a guess, I haven't tested it.

    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").

    Documentation here refers to DOM elements, even if it's not explicit.

    In fact, if it DOES work without a user gesture before showing the dialog, I'd consider that a bug, since the user has no way to avoid interacting with a confirm.