Check whether user has a Chrome extension installed

前端 未结 16 2097
一向
一向 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条回答
  •  旧时难觅i
    2020-11-22 09:21

    I used the cookie method:

    In my manifest.js file I included a content script that only runs on my site:

     "content_scripts": [
            {
            "matches": [
                "*://*.mysite.co/*"
                ],
            "js": ["js/mysite.js"],
            "run_at": "document_idle"
            }
        ], 
    

    in my js/mysite.js I have one line:

    document.cookie = "extension_downloaded=True";
    

    and in my index.html page I look for that cookie.

    if (document.cookie.indexOf('extension_downloaded') != -1){
        document.getElementById('install-btn').style.display = 'none';
    }
    

提交回复
热议问题