0

I have a Firefox extension that adds event listeners to all elements on a website through a content script:

document.addEventListener('click', function eventHandler(e) {
   // do something
})

This works fine in most cases, but the eventHandler function is not triggered when clicking on elements in dynamically created iframes, for example, the form on the right on https://www.deepl.com/contact-us?cta=whydeepl

The "all_frames": true flag in the manifest is set, and it is configured to match all URLs, so that shouldn't be the issue.

Is there a way to get this to work?

lua
  • 86
  • 4
  • I think you would need some event delegation for that dynamic content. i.e. single click handler on body. https://stackoverflow.com/questions/34896106/attach-event-to-dynamic-elements-in-javascript – dmoo Jun 09 '22 at 13:28
  • Doesn't attaching the listener directly to the document already make it so that the event is only handled after it has been delegated to the highest level? – lua Jun 09 '22 at 14:01
  • 1
    Try adding `"match_about_blank": true` as well. – wOxxOm Jun 09 '22 at 14:55
  • Yep that worked. Weird that there is an extra flag for that. Thanks! – lua Jun 09 '22 at 15:44

1 Answers1

0

Solved: Just needed to set "match_about_blank": true in the manifest.

lua
  • 86
  • 4