0

Im trying to have a page talk to an extension using chrome.extension.connect, but the chrome.extension object isnt available.

If I console.log(chrome) I get an object with:

app
appNotifications
csi
loadTimes
searchBox
setSuggestResult
webstore

But no extension.

Do I need to do something to enable this? Or any reason it would not be available?

Im using Chrome 20 on OSX 10.7

Adam Meyer
  • 1,505
  • 1
  • 19
  • 28
  • 1
    "A page talk to an extension". A page cannot directly communicate with an extension. The extension has to implement such a feature using content scripts. For inspiration/sample code, see [this Stack Overflow answer](http://stackoverflow.com/questions/9602022/chrome-extension-retrieving-gmails-original-message/9636008#9636008). – Rob W Jul 22 '12 at 21:33

1 Answers1

1

Choose the developer mode in chrome://chrome/extensions/, then you will be able to use the Chrome devtool to inspect the extension's background page, and chrome.extension is there. chrome.extension is NOT shown in ordinary pages, but only in extensions.

chaohuang
  • 3,965
  • 4
  • 27
  • 35
  • more specifically - chrome.extension.connect cannot be accessed by the JavaScript of an ordinary page, it can only be accessed by the extension's own [content scripts](https://code.google.com/chrome/extensions/content_scripts.html) running on that page. – gengkev Jul 22 '12 at 18:30
  • And if you look at the page gengkev pointed to there is an example of a content script communicating with its host page... http://code.google.com/chrome/extensions/content_scripts.html#host-page-communication ...also, you could make one of your extensions pages web accessible and have the page that wants to communicate with your extension load it in` an invisible iframe and then post messages to it. The message could simply be its url that your extension then scans the tabs for and injects a content script that is then used for communication. – PAEz Jul 22 '12 at 18:40