Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Google Chrome Browser Extensions

I was looking for a way to detect the browser extension I am building from my website and I need to alert my users in-case they are viewing my site without it. I have been able to do this in firefox, but I want to know is there a way I can do this in Google Chrome? Even if there is a hack to get this going I am fine.

like image 489
Ajay Prabhakar Avatar asked Oct 15 '22 08:10

Ajay Prabhakar


1 Answers

Sure. Create a content script specific to you site in the extension, and make it add an invisible marker in the DOM, eg:

$('body').append('<div style="display: none;" class="extension_enabled" />');

In the page, set a short timeout to check for this after the document is fully loaded, eg:

$(function() {
  setTimeout(function() {
    if ($('.extension_enabled').length > 0) {
      alert('Installed!');
    } else {
      alert('Not installed.');
    }
  }, 500);
});

NOTE: Code in jQuery format for simplicity. You can do it with raw javascript, of course.

like image 175
Max Shawabkeh Avatar answered Oct 21 '22 03:10

Max Shawabkeh