Check whether user has a Chrome extension installed

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

    I am sure there is a direct way (calling functions on your extension directly, or by using the JS classes for extensions), but an indirect method (until something better comes along):

    Have your Chrome extension look for a specific DIV or other element on your page, with a very specific ID.

    For example:

    Do a getElementById and set the innerHTML to the version number of your extension or something. You can then read the contents of that client-side.

    Again though, you should use a direct method if there is one available.


    EDIT: Direct method found!!

    Use the connection methods found here: https://developer.chrome.com/extensions/extension#global-events

    Untested, but you should be able to do...

    var myPort=chrome.extension.connect('yourextensionid_qwerqweroijwefoijwef', some_object_to_send_on_connect);
    

提交回复
热议问题