Check whether user has a Chrome extension installed

前端 未结 16 2295
一向
一向 2020-11-22 08:50

I am in the process of building a Chrome extension, and for the whole thing to work the way I would like it to, I need an external JavaScript script to be able to detect if

16条回答
  •  时光取名叫无心
    2020-11-22 09:27

    If you're trying to detect any extension from any website, This post helped: https://ide.hey.network/post/5c3b6c7aa7af38479accc0c7

    Basically, the solution would be to simply try to get a specific file (manifest.json or an image) from the extension by specifying its path. Here's what I used. Definitely working:

    const imgExists = function(_f, _cb) {
        const __i = new Image();
        __i.onload = function() {
            if (typeof _cb === 'function') {
                _cb(true);
            }
        }
        __i.onerror = function() {
            if (typeof _cb === 'function') {
                _cb(false);
            }
        }
        __i.src = _f;
        __i = null;
    });
    
    try {
        imgExists("chrome-extension://${CHROME_XT_ID}/xt_content/assets/logo.png", function(_test) {
            console.log(_test ? 'chrome extension installed !' : 'chrome extension not installed..');
            ifrm.xt_chrome = _test;
            // use that information
        });
    } catch (e) {
        console.log('ERROR', e)
    }
    

提交回复
热议问题