I have a dire need to implement the following:
- Collect and structure data from http://source.site (no injection needed, just DOM)
- Pass it somehow the background script (workers in V3? so confusing)
- Register global hotkeys for the extension accessible on any
*
normal page/all tabs/everywhere - When specific hotkey is pressed, the data that was sent to the background script earlier is inserted into clipboard (or active element of type
INPUT
)
Issues with #2: How can I pass complex object/data it to persistent background worker that ALWAYS active, even if all tabs/pages closed and just startup page open? I know you can use convoluted and ugly window.postMessage
to communicate between injected and content scripts - is it the same here?
Issues with #3: after some extensive googling I found out that with manifest V3 google also tightened this and now super-global
hotkeys are not possible from background scripts. So my only choice is to ALWAYS execute content script on *
addresses and just write old good window.onkeydown
?
Issues with #4: it appears only injected scripts can affect clipboard. Current active/focused element can be accessed from content script so I'm back to applying content scripts to every web-site then?
Right now, the only way I see this being done is:
- execute parsing on a hotkey registered on content script and collect data if URI matches http://source.site
- store data in extension's localStorage?
- on tab focus event, check if the URI != http://source.site and then fetch data so it is ready
- register the rest of the hotkeys and insert data on press
But it feels like there has to be a better, more sane way.