summaryrefslogtreecommitdiff
path: root/ext/js/comm
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-11-21 15:08:39 -0500
committerGitHub <noreply@github.com>2021-11-21 15:08:39 -0500
commit06e70c1cd8a6e23b54ba9081caf82902820ceccd (patch)
treeb4b05d6a878285bd9c43962e33716ce7aadead55 /ext/js/comm
parent36967b18397dc7f6414d81584ea37f364195b164 (diff)
FrameOffsetForwarder fixes (#2017)
* Fix handling of null iframe rect * Handle errors inside of getOffset
Diffstat (limited to 'ext/js/comm')
-rw-r--r--ext/js/comm/frame-offset-forwarder.js33
1 files changed, 19 insertions, 14 deletions
diff --git a/ext/js/comm/frame-offset-forwarder.js b/ext/js/comm/frame-offset-forwarder.js
index dd064a64..d8e3fa4f 100644
--- a/ext/js/comm/frame-offset-forwarder.js
+++ b/ext/js/comm/frame-offset-forwarder.js
@@ -37,24 +37,29 @@ class FrameOffsetForwarder {
return [0, 0];
}
- const ancestorFrameIds = await this._frameAncestryHandler.getFrameAncestryInfo();
+ try {
+ const ancestorFrameIds = await this._frameAncestryHandler.getFrameAncestryInfo();
- let childFrameId = this._frameId;
- const promises = [];
- for (const frameId of ancestorFrameIds) {
- promises.push(yomichan.crossFrame.invoke(frameId, 'FrameOffsetForwarder.getChildFrameRect', {frameId: childFrameId}));
- childFrameId = frameId;
- }
+ let childFrameId = this._frameId;
+ const promises = [];
+ for (const frameId of ancestorFrameIds) {
+ promises.push(yomichan.crossFrame.invoke(frameId, 'FrameOffsetForwarder.getChildFrameRect', {frameId: childFrameId}));
+ childFrameId = frameId;
+ }
- const results = await Promise.all(promises);
+ const results = await Promise.all(promises);
- let xOffset = 0;
- let yOffset = 0;
- for (const {x, y} of results) {
- xOffset += x;
- yOffset += y;
+ let x = 0;
+ let y = 0;
+ for (const result of results) {
+ if (result === null) { return null; }
+ x += result.x;
+ y += result.y;
+ }
+ return [x, y];
+ } catch (e) {
+ return null;
}
- return [xOffset, yOffset];
}
// Private