0

How to inject content scripts when the icon is clicked, without using onClicked.addListener() in the background page, because this will prevents the popup from showing up.

I want the popup to display and a content script to be injected simultaneously (to get the text highlighted in the page)

mockingjay
  • 181
  • 1
  • 10
  • 1
    What have you tried? We are confused as to what your problem is. Have you tried to do it? Do you have code that at least shows the popup? Basically, as already stated, you just do it the same way you would have in a `chrome.browserAction.onClicked` listener (i.e. using `chrome.tabs.executeScript()`). Because your question implies that you know how to do this in a `chrome.browserAction.onClicked` listener, without you providing a [mcve], we are unsure what your issue is with respect to not being able to do this in a popup. – Makyen Jan 24 '17 at 01:37
  • if call the script from the popup I wont have access to the page content – mockingjay Jan 24 '17 at 03:41
  • See [How to access the webpage DOM rather than the extension page DOM?](//stackoverflow.com/q/4532236) – wOxxOm Jan 24 '17 at 03:50
  • I would suggest that you read the [Chrome extension overview](https://developer.chrome.com/extensions/overview) (and perhaps along with the pages linked from the overview). The [architecture section](https://developer.chrome.com/extensions/overview#arch) has overall architecture information which should help your understanding of how things are generally organized/done. – Makyen Jan 24 '17 at 06:32
  • If you are just looking for code, the answer to [Execute script after click in popup.html (chrome extension)](http://stackoverflow.com/questions/20764517/execute-script-after-click-in-popup-html-chrome-extension) has a link to a gist with code which will do what you want. – Makyen Jan 24 '17 at 06:46

0 Answers0