In a webpage, how can I detect that a particular extension is loaded in a browser? [duplicate]

无人久伴 提交于 2019-12-13 11:10:11

问题


I was asked to display a pop-up to the user if he has at least 1 out of 5 extensions.

The extensions are: adblock plus,adBlock,Disconnect and etc...

I am not familiar with all the extensions and their affect on the DOM (except for adblock plus) so I am looking for a function that will check by the extension id if it exist in the browser?

I tried:

var detect = function(base, if_installed, if_not_installed) {
    var s = document.createElement('script');
    s.onerror = if_not_installed;
    s.onload = if_installed;
    document.body.appendChild(s);
    s.src = base + '/manifest.json';
}
detect('chrome-extension://' + 'gcbommkclmclpchllfjekcdonpmejbdp', function() {alert('boom!');});

Which I got from:http://blog.kotowicz.net/2012/02/intro-to-chrome-addons-hacking.html, He says it works, but I got this error:

Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.


回答1:


That extension probably makes changes to the HTML headers or at least something in the DOM. So figure out what that change might be and detect that using JS.

If that is no good, take a look here.
Check whether user has a Chrome extension installed




回答2:


You can check current protocol with window.location.protocol



来源:https://stackoverflow.com/questions/40345467/in-a-webpage-how-can-i-detect-that-a-particular-extension-is-loaded-in-a-browse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!