alykoshin/inline-install

View on GitHub
demo/index.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>InlineInstall demo page</title>

  <script src="./node_modules/mini-emitter/index.js"></script>
  <script src="./node_modules/inline-install/index.js"></script>

  <!--<script src="../index.js"></script>-->

  <script>
    //    var InlineInstall = require('inline-install');

    if ( window.chrome ) {

      var inlineInstall = new InlineInstall({
        // Extension Id in Chrome Web Store. Replace <itemId> with your
        // value which is a part of extension url
        // 'https://chrome.google.com/webstore/detail/<itemId>'
        itemId: 'hodfoeopgcbbmgcmmgflnnobeckekogk',
        // Check if the extension is already installed in the browser
        checkInstalled: true,
        // Object defining the prompt to be show to the user
        prompt: {
          // Inline Install must be initiated by user action;
          // if you start this installation code by some user action,
          // you may set `prompt.enabled` to `false` to avoid default prompt to be shown
          enabled: true,
          // Prompt text
          text: 'This site requires Chrome Extension to be installed. Proceed?',
        },
        // Reload current page in browser after successful installation
        reloadOnSuccess: true
      });

      inlineInstall.on('error', function(errorString, errorCode) {
        alert( 'InlineInstall: Error: ' + errorString +
          ', code: ' + (errorCode || '') );
      });

      inlineInstall.on('downloadprogress', function(percentDownloaded) {
        console.log('InlineInstall: Download Progress: '+percentDownloaded+'%');
      });

      inlineInstall.on('installstagechanged', function(installStage) {
        console.log('InlineInstall: Install Stage changed'+
          ', new stage: \'' + installStage + '\'');
      });

      inlineInstall.on('success', function() {
        console.log('InlineInstall: Extension is installed.');
      });

      inlineInstall.execute();
    }

  </script>
</head>
<body>

<p>This demo may be opened only locally in Chrome</p>

</body>
</html>