FrameOffsetForwarder fixes (#2017)
* Fix handling of null iframe rect * Handle errors inside of getOffset
This commit is contained in:
parent
36967b1839
commit
06e70c1cd8
@ -316,12 +316,7 @@ class PopupProxy extends EventDispatcher {
|
|||||||
async _updateFrameOffsetInner(now) {
|
async _updateFrameOffsetInner(now) {
|
||||||
this._frameOffsetPromise = this._frameOffsetForwarder.getOffset();
|
this._frameOffsetPromise = this._frameOffsetForwarder.getOffset();
|
||||||
try {
|
try {
|
||||||
let offset = null;
|
const offset = await this._frameOffsetPromise;
|
||||||
try {
|
|
||||||
offset = await this._frameOffsetPromise;
|
|
||||||
} catch (e) {
|
|
||||||
// NOP
|
|
||||||
}
|
|
||||||
this._frameOffset = offset !== null ? offset : [0, 0];
|
this._frameOffset = offset !== null ? offset : [0, 0];
|
||||||
if (offset === null) {
|
if (offset === null) {
|
||||||
this.trigger('offsetNotFound');
|
this.trigger('offsetNotFound');
|
||||||
|
@ -37,24 +37,29 @@ class FrameOffsetForwarder {
|
|||||||
return [0, 0];
|
return [0, 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
const ancestorFrameIds = await this._frameAncestryHandler.getFrameAncestryInfo();
|
try {
|
||||||
|
const ancestorFrameIds = await this._frameAncestryHandler.getFrameAncestryInfo();
|
||||||
|
|
||||||
let childFrameId = this._frameId;
|
let childFrameId = this._frameId;
|
||||||
const promises = [];
|
const promises = [];
|
||||||
for (const frameId of ancestorFrameIds) {
|
for (const frameId of ancestorFrameIds) {
|
||||||
promises.push(yomichan.crossFrame.invoke(frameId, 'FrameOffsetForwarder.getChildFrameRect', {frameId: childFrameId}));
|
promises.push(yomichan.crossFrame.invoke(frameId, 'FrameOffsetForwarder.getChildFrameRect', {frameId: childFrameId}));
|
||||||
childFrameId = frameId;
|
childFrameId = frameId;
|
||||||
|
}
|
||||||
|
|
||||||
|
const results = await Promise.all(promises);
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
const results = await Promise.all(promises);
|
|
||||||
|
|
||||||
let xOffset = 0;
|
|
||||||
let yOffset = 0;
|
|
||||||
for (const {x, y} of results) {
|
|
||||||
xOffset += x;
|
|
||||||
yOffset += y;
|
|
||||||
}
|
|
||||||
return [xOffset, yOffset];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private
|
// Private
|
||||||
|
Loading…
Reference in New Issue
Block a user