1

Possible Duplicate:
Check whether user has my chrome extension installed

A little background. I'm creating a Chrome extension to interact with data between a company's intranet site to open and login to social media sites. I want to write buttons on a page with Javascript only if I have verified that the extension actually exists in that browser. The button is useless otherwise. Let me know if you've found a clean way to do that!

Thanks!

Community
  • 1
  • 1
Chris Jenkins
  • 719
  • 7
  • 20
  • @If the extension is not installed, the code would not run at all..can you be little more clear? are you looking for two chrome extensions communication? – Sudarshan Dec 08 '12 at 03:56
  • I have no idea how extensions work, but in the case that they add functionality to the page (a few utility functions, an object with methods, etc.) then just check for its presence like `if ("myExtensionObject" in window) {}` – Ian Dec 08 '12 at 05:32

1 Answers1

2

Write buttons on a page with JavaScript, from your Extension.

Find below the way you can.

manifest.json

{

  "name": "Example",

  "description": "Description",

  "version": "0.6",

  "permissions": ["tabs", "http://mysite.com/*"],

  "background": {

    "scripts": ["background.js"]

  },

  "manifest_version": 2

}

background.js

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
  var HOST_NAME = 'mysite.com';
  if(changeInfo.status === "complete")
  if(tab.url.search(HOST_NAME) !== -1) {
    var execute_script_param = { "file": "excecute_js.js",
                                 "runAt": "document_start"
                               }
    chrome.tabs.executeScript(tabId, execute_script_param, function() {
      console.log('added extension identity in dom');
      // if you want to do here, go ahead
    })
  }
});

excecute_js

(function(obj_document) {
  // do here what ever you want
  // write buttons on a page with Javascript
})(window.document)
Raghvendra Parashar
  • 3,883
  • 1
  • 23
  • 36
  • 1
    How does this answer OP's question `I want to write buttons on a page with Javascript only if I have verified that the extension actually exists in that browser`? – Sudarshan Dec 08 '12 at 08:09
  • 1
    As you have mentioned that, you want to check your extension is installed or not. And after verify you will show buttons on your website using JavaScript, so you can write JavaScript at Extension site also. – Raghvendra Parashar Dec 08 '12 at 18:11