JavaScript check if browser extension is installed for Chrome, Firefox and Opera
Asked Answered
N

1

6


I want to show custom bar ( notification like: Install our plugin. ) on our site if extension is not installed for Chrome, Firefox and Opera. None will be displayed if extension is installed.

The idea is:
1. User visits our site and a bar with message appears - "Hey, install our extensions".
2. User clicks on install and extension is installed. No need for the user to open it.
3. User visit our site again and the bar does not appear again as the extension is installed.
We talk only for installation check, not cookies.

So far I was able to find solutions only for Chrome: http://blog.kotowicz.net/2012/02/intro-to-chrome-addons-hacking.html
and Firefox: http://webdevwonders.com/detecting-firefox-add-ons/
Opera is never mentioned.

Is there a way to do it for Opera, based on the idea of checking for a local resource which is part of the extension:
chrome-extension://--Extension ID--/blank.gif
Firefox chrome://firebug/content/blank.gif

Or else: Is there a simple way to check if extension is installed for Chrome, Firefox and Opera?

Nosepiece answered 18/1, 2013 at 12:2 Comment(10)
It's quite easy if the extension is willing to cooperatePyroelectricity
Or if that extension leaves traceable info like some unique element or attributes in DOM.Toby
Or if that extension leaves something in the global scope - that's what I meant by cooperationPyroelectricity
If you're trying to autodetect adblock, you could give it a honeypot - or just test the presence of the real ads you've added.Pyroelectricity
So, what is the extension you're trying to detect?Pyroelectricity
The extension is just a shell that displays a webpage. Nothing to do with AdBlock. @Jan Dvorak How to cooperate? I want for the page that shows the bar to know is the extension is installed despite of that it is ever opened.Nosepiece
@Nosepiece if the bar is added to the dom, it should be easy to find it there from outside the extension.Pyroelectricity
@Jan Dvorak I've updated the question with the user story. I hope the idea get clearer now.<br /> I search for connection from the browsers page with the extension not the other way around.Nosepiece
@Nosepiece why not let the extension advertise its presence to the document, if the document wants to know whether the extension is present?Pyroelectricity
Does this answer your question? Check if user has a third party Chrome extension installedLend
P
4

If the extension is willing to cooperate, it could advertise its presence to the document easily. For example:


The extension could do

window.$$myExt = ...

Then you can detect the extension by

if(typeOf $$myExt !== 'undefined'){...

(or any variation thereof)

Obtaining the page window is somewhat tricky at least


The extension could do

document.body.classList.add("myExt-visited")

Then you could detect the extension by

if(document.body.classList.contains("myExt-visited")){...

The extension could do

document.body.innerHTML += "<div id='myExt-toolbar'>..."
// or $('body').append("<div id='myExt-toolbar'>...");

then you could detect the extension by

if(document.getElementByID("myExt-toolbar")){...
// or if($("#myExt-toolbar").length){...

alternatively, you could do

<div id="myExt-replacement">
   ...

and the extension would do

var replacement = document.getElementByID("myExt-replacement");
replacement && replacement.remove();

or you could do

function onMyExtExists(){
  ...
}

and the extension would do

onMyExtExists && onMyExtExists();
Pyroelectricity answered 18/1, 2013 at 12:36 Comment(6)
Well, this is obviously the only one possible solution as in Opera the browser js can't check in an extension is installed. I hope I can write back with detailed solution later.Nosepiece
Where in the extension architecture would window.$$myExt = ... go?Gambol
@Gambol as soon as it wants to be detectable. That is, as soon as possible, because the extension detection cannot run before the extension makes itself visible.Pyroelectricity
The 'window' object in an extension is not the same 'window' as the website. They cannot communicate via that channel.Diamagnetic
@Diamagnetic would unsafeWindow work for that purpose? If not, what would?Pyroelectricity
@Diamagnetic struck out. Should I remove the paragraph completely?Pyroelectricity

© 2022 - 2024 — McMap. All rights reserved.