问题
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