On certain sites, when modal dialogs are open, interacting with our content script UI is affecting the 'outside click' handlers for the webpage's modals, causing them to close
My intent is to add 'capture phase' event listeners to the root-most element before the page adds it's own listeners, thus allowing me to stopImmediatePropagation
if the event.target is within our UI (preventing the page's click handlers from even knowing or running)
I'm not familiar enough with chrome apis (webNavigation?) to know if there is a time when I can add these listeners before any <script>
within the served page is executed.
I attempted to add a plain text / string version of our eventTrap.js
inside of a <script>
tag and add it to the page, but this violates content security policy (extensions run in "isolated worlds" by default)
I have also tried using document_start
and ensuring that our element is the last in the DOM (after the large click trap element), with a higher z-index and non-static position.
How can I inject a script that runs before anything on the page itself??
My current thinking is that I can somehow listen for a webNavigation
event in the service worker, and somehow modify the webpage, maybe using chrome.scripting.executeScript
The current case is https://repl.it after clicking 'Create Repl' to open a modal. We need modals like this to stay open while interacting with our UI. Another website with similar, overly aggressive capturing is https://notion.so (usually with keystrokes in that case).