Svadilfari
Svadilfari copied to clipboard
Prevent unnecessary events sent to iframes
The content script runs on every frame, including all iframes on the page. The gesture recognizer runs on each frame so that gestures can be performed in frames.
Because we want to display the HUD in the top frame, instead of a small iframe, we forward the events through background.js
.
Ideally, such forwarding events should only be delivered to the top frame, but it seems that Safari does not respect the third argument of tabs.sendMessage
and flood events.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/sendMessage
The simplest workaround is to check window.self !== window.top
on receiving messages from the background page not to process forwarded events on iframes. While it works as expected, this might affect performance especially if there are many iframes.
https://developer.apple.com/safari/technology-preview/release-notes/#:~:text=Added%20support%20for%20the%20frameId%20option%20that%20can%20be%20passed%20to%20browser.tabs.sendMessage()
It seems that they added support for frameId
in browser.tabs.sendMessage()
. I will have a closer look.