2

I have created browser extension/add-on for Chrome, Firefox, Safari and IE using Crossrider framework
Now since Crossrider does not provide support for Opera, I have created a native extension for the same.
My problem is how to detect if a user(using Opera), visiting our website, has the extension installed or not ?

Similar Question is answered. Is there any better option?

Or any simple way to check(crossbrowser) if an extension is installed or not so that I don't have to use Crossrider.API?

Or is there anything similar to window.navigator.plugins for extensions?

Community
  • 1
  • 1
Uttara
  • 2,496
  • 3
  • 24
  • 35

1 Answers1

0

You can communicate with your page using simple content script for your domain only using window.postMessage function.

Content script code:

window.addEventListener("message", function(event) {
  if (event.source !== window) return;  // We only accept messages from ourselves
  switch (event.data.type) {
    case 'get_info': window.postMessage({type: "info", browser: 'opera'}, "*"); break;
  }
}, false);

Your page code:

window.addEventListener('load', function () {
  window.addEventListener("message", function (event) {
    switch (event.data.type) {
      case 'info': console.log(`browser is ${event.data.browser}`); break;
    }
  });
  window.postMessage({type: "get_info"}, "*");    
});
icl7126
  • 5,740
  • 4
  • 53
  • 51