0

I created a simple Firefox extension to show an external page in a popup. I was now wondering if it's possible to use the content from the external page to fill a field in the current tab or if this is only possible when loading the content natively.

Basically what I'm trying to do is:

  • Open a webpage
  • The webpage contains an input field
  • Open the extension > popup appears
  • Click an item inside the popup
  • Use the content of the item clicked as value for a (or all) input fields in the current tab
vespino
  • 1,714
  • 3
  • 15
  • 28
  • You can declare a content script that runs on the source page and use browser.runtime.sendMessage in a click listener. The background script will listen (browser.runtime.onMessage) and use browser.tabs.executeScript to run a content script in the active tab, which will use the value either from messaging or from browser.storage.local. – wOxxOm Feb 22 '21 at 14:21
  • @wOxxOm thanks again for your response. Your example helped me greatly last time. I found the default content script inserting a border around a website. That is what you're talking about, right? Will this work when the source page is redirected like the way I set it up? – vespino Feb 22 '21 at 14:34
  • I don't know what "default content script" and "border around a website" means. Use my above comment as a hint to find more info. – wOxxOm Feb 22 '21 at 14:38
  • I meant this script: https://github.com/tsl143/tutorials/tree/master/contentScript – vespino Feb 22 '21 at 14:47
  • Yes, the first one is a content script declared in manifest.json, the second one is injected via executeScript. – wOxxOm Feb 22 '21 at 14:51
  • You provided me with a script redirecting the default page to my external page. Will this work after redirection? – vespino Feb 22 '21 at 14:53
  • Try it and see :-) – wOxxOm Feb 22 '21 at 14:53
  • Nope, the external page won't be able to interact with the background script and since this is only a one person internal tool, I'm not diving into getting the data natively. So I'll leave things as they are. – vespino Feb 22 '21 at 15:11
  • The content script that runs there will be able to use sendMessage, this is what my first comment said. – wOxxOm Feb 22 '21 at 15:17
  • So basically: add a background script and from the external page write to local storage what I want to insert into an input field? Sorry... still a newby. – vespino Feb 22 '21 at 15:20

0 Answers0