Check whether user has a Chrome extension installed

前端 未结 16 2075
一向
一向 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:14

    If you have control over the Chrome extension, you can try what I did:

    // Inside Chrome extension
    var div = document.createElement('div');
    div.setAttribute('id', 'myapp-extension-installed-div');
    document.getElementsByTagName('body')[0].appendChild(div);
    

    And then:

    // On web page that needs to detect extension
    if ($('#myapp-extension-installed-div').length) {
    
    }
    

    It feels a little hacky, but I couldn't get the other methods to work, and I worry about Chrome changing its API here. It's doubtful this method will stop working any time soon.

提交回复
热议问题