3

I am trying to open/interact with the chrome extension from the webpage in my local(Not installed the chrome extension from the web store). For that, i have this piece of code

chrome.runtime.sendMessage(extensionId, {}, function(){ // code })

Here extensionId is the ID which i manually copied from the chrome extension. And it is working.

Is there any way to get the chrome extension ID programmatically in the webpage? Or is there any other way to open/interact with the chrome extension programmatically?

Sam
  • 2,275
  • 9
  • 30
  • 53
  • 2
    No, but the extension can expose itself to the page via a standard DOM CustomEvent, [example](https://stackoverflow.com/a/19312198). – wOxxOm Jun 19 '20 at 14:00
  • Thanks for the reply. I am new to the chrome ext, where i have to add the code. What i did is, added `On the receiving side` code added in background.js and `On the initiator side` code added in the webpage. This case it is not working. Did i miss any thing? – Sam Jun 19 '20 at 14:33
  • As the answer says the communication is between the *content script* and the page script. – wOxxOm Jun 19 '20 at 14:44
  • I just updated the question with your code, still chrome ext is not opening. Let me know if i miss any thing. – Sam Jun 19 '20 at 15:16
  • Content scripts can't use chrome.windows API. – wOxxOm Jun 19 '20 at 15:36
  • Yeah, so i just wanted to open a chrome ext from the web page. So you think i have to use the chrome ext id for that? is that only way? – Sam Jun 19 '20 at 16:24
  • 1
    The content script can send a [message](https://developer.chrome.com/extensions/messaging) to its background script, which will create the window. – wOxxOm Jun 19 '20 at 16:25

1 Answers1

2

This is a little old, but this answer to my question answers you directly. You may use chrome.runtime.id to fetch this value. Cheers

HydroPage
  • 121
  • 12