How can I detect if the user of my site has my extension installed in Chrome / Moziilla

4

Hello, I need to detect if users who visit my site already have my installed extension, some functions of the site depend on this extension.

If you have the extension installed you can access it normally and if you do not have a warning that indicates the link to the installation in Chrome and Mozilla.

    
asked by anonymous 06.02.2017 / 02:46

1 answer

6

In this question has a very simple and functional code . The code below will attempt to load a cross-schema script from chrome-extension: // URL , in this case - the manifest file. You only need the unique ID to put in the URL. If the extension is installed, manifest will load and onload event will fire, if not onerror . Remember that for you to be able to communicate with the Extension and your site, in% with% of the extension it must have manifest.json .

Code:

function Ext_NotInstallada(ExtName, ExtID) {
    console.log(ExtName + ' --Não Installada!');
    if (msg.innerHTML != '')
        msg.innerHTML = msg.innerHTML + "<BR>"

    msg.innerHTML = msg.innerHTML + ExtName + ' _Clique no link para obter a extensão! <a href="https://chrome.google.com/webstore/detail/locallinks/' + ExtID + '">here</a>';
}

function Ext_Installada(ExtName, ExtID) {
    console.log(ExtName + ' Instalada');
}

var Detectar_Extensao = function(Name, ID) {
    var s = document.createElement('script');
    s.onload = function() {
        Ext_Installada(Name, ID);
    };
    s.onerror = function() {
        Ext_NotInstallada(Name, ID);
    };
    s.src = 'chrome-extension://' + ID + '/manifest.json';
    document.body.appendChild(s);
}

$(function() {
    var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

    if (is_chrome)
        Detectar_Extensao('__MSG_CHROME_HANGOUTS_SHORT_NAME__', 'jifpbeccnghkjeaalbbjmodiffmgedin');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid='msg'></div>

Testwith Hangouts .

The ID is in the URL

Youcangetdetailsof"web_accessible_resources": ["*"] following this Tutorial .

  • Install the Chrome Extension Source Code Viewer

  • Open your Apps and click CRX, the previously installed extension.

  • Clicking View Source, you will see details of the file.
  •     
    06.02.2017 / 11:25