aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-18 00:33:49 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2020-04-18 23:28:00 +0300
commitfbaf50def1934ef6fe0967233f4419efc44f1c30 (patch)
tree152338f0b00524033c4078008e9558423ad631df /ext/fg/js
parent4fdc300b61ebc3d36c3f5a511df92248453f8d55 (diff)
support iframes inside open shadow dom
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/frame-offset-forwarder.js23
1 files changed, 21 insertions, 2 deletions
diff --git a/ext/fg/js/frame-offset-forwarder.js b/ext/fg/js/frame-offset-forwarder.js
index c658c55a..ac6e617d 100644
--- a/ext/fg/js/frame-offset-forwarder.js
+++ b/ext/fg/js/frame-offset-forwarder.js
@@ -79,9 +79,28 @@ class FrameOffsetForwarder {
sourceFrame = frame;
break;
}
+
if (sourceFrame === null) {
- this._forwardFrameOffsetOrigin(null, uniqueId);
- return;
+ const getShadowRootElements = (documentOrElement) => {
+ const elements = Array.from(documentOrElement.querySelectorAll('*'))
+ .filter((el) => !!el.shadowRoot);
+ const childElements = elements
+ .map((el) => el.shadowRoot)
+ .map(getShadowRootElements);
+ elements.push(childElements.flat());
+
+ return elements.flat();
+ };
+
+ sourceFrame = getShadowRootElements(document)
+ .map((el) => Array.from(el.shadowRoot.querySelectorAll('frame, iframe:not(.yomichan-float)')))
+ .flat()
+ .find((el) => el.contentWindow === e.source);
+
+ if (!sourceFrame) {
+ this._forwardFrameOffsetOrigin(null, uniqueId);
+ return;
+ }
}
const [forwardedX, forwardedY] = offset;