Don't parent the popup frame to elements which cause unload (#488)

This commit is contained in:
toasted-nutbread 2020-05-02 12:58:24 -04:00 committed by GitHub
parent 401fe9f8d0
commit 8a368aaddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -281,7 +281,7 @@ class Popup {
}
_onFullscreenChanged() {
const parent = (DOM.getFullscreenElement() || document.body || null);
const parent = this._getFrameParentElement();
if (parent !== null && this._container.parentNode !== parent) {
parent.appendChild(this._container);
}
@ -375,6 +375,22 @@ class Popup {
contentWindow.postMessage({action, params, token}, this._targetOrigin);
}
_getFrameParentElement() {
const defaultParent = document.body;
const fullscreenElement = DOM.getFullscreenElement();
if (fullscreenElement === null || fullscreenElement.shadowRoot) {
return defaultParent;
}
switch (fullscreenElement.nodeName.toUpperCase()) {
case 'IFRAME':
case 'FRAME':
return defaultParent;
}
return fullscreenElement;
}
static _getPositionForHorizontalText(elementRect, width, height, viewport, offsetScale, optionsGeneral) {
const preferBelow = (optionsGeneral.popupHorizontalTextPosition === 'below');
const horizontalOffset = optionsGeneral.popupHorizontalOffset * offsetScale;