How to detect extension on a browser?

前端 未结 2 1921
悲&欢浪女
悲&欢浪女 2020-12-12 05:31

I\'m trying to detect if an extension is installed on a user\'s browser.

I tried this:

var detect = function(base, if_installed, if_not_installed) {
         


        
相关标签:
2条回答
  • 2020-12-12 06:05

    The first error is informative from Chrome, injected directly into the console and not catchable by you (as you noticed).

    The GET errors are from the network stack. Chrome denies load in either case and simulates a network error - which you can catch with onerror handler on the element itself, but not in the window.onerror hander. Quote, emphasis mine:

    When a resource (such as an <img> or <script>) fails to load, an error event using interface Event is fired at the element, that initiated the load, and the onerror() handler on the element is invoked. These error events do not bubble up to window, but (at least in Firefox) can be handled with a single capturing window.addEventListener.

    Here's an example that will, at least, detect the network error. Note that, again, you can't catch them, as in prevent it from showing in the console. It was a source of an embarrasing problem when Google Cast extension (that was exposing a resource) was using it as a detection method.

    s.onload = function(){alert("installed")}; 
    s.error = function(){alert("I still don't know")};
    

    Notice that you can't distinguish between the two. Internally, Chrome redirects one of the requests to chrome-extension://invalid, but such redirects are transparent to your code: be it loading a resource (like you do) or using XHR. Even the new Fetch API, that's supposed to give more control over redirects, can't help since it's not a HTTP redirect. All it gets is an uninformative network error.

    As such, you can't detect whether the extension is not installed or installed, but does not expose the resource.


    Please understand that this is intentional. The method you refer to used to work - you could fetch any resource known by name. But it was a method of fingerprint browsers - something that Google is explicitly calling "malicious" and wants to prevent.

    As a result, web_accessible_resources model was introduced in Chrome 18 (all the way back in Aug 2012) to shield extensions from sniffing - requiring to explicitly declare resources that are exposed. Quote, emphasis mine:

    Prior to manifest version 2 all resources within an extension could be accessed from any page on the web. This allowed a malicious website to fingerprint the extensions that a user has installed or exploit vulnerabilities (for example XSS bugs) within installed extensions. Limiting availability to only resources which are explicitly intended to be web accessible serves to both minimize the available attack surface and protect the privacy of users.

    With Google actively fighting fingerprinting, only cooperating extensions can be reliably detected. There may be extension-specific hacks - such as specific DOM changes, request interceptions or exposed resources you can fetch - but there is no general method, and extension may change their "visible signature" at any time. I explained it in this question: Javascript check if user has a third party chrome extension installed, but I hope you can see the reason for this better.

    To sum this up, if you indeed were to find a general method that exposed arbitrary extensions to fingerprinting, this would be considered malicious and a privacy bug in Chrome.

    0 讨论(0)
  • 2020-12-12 06:26

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

    For example:-

    <div id="ExtensionCheck_JamesEggersAwesomeExtension"></div>
    
    0 讨论(0)
提交回复
热议问题