From dac33e696145ad3c2cfe076a7fadc82c05732102 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 18 Jul 2020 14:15:36 -0400 Subject: Extension unload indication fix (#662) * Remove unused function * Rename field * Change extensionUnloaded trigger function * Update how extension unloaded content is shown * Ignore certain errors caused by extension unload * Add _showExtensionUnloaded function * Wrap internals of updateOptions * Suppress errors caued by extension unload * Make the frontend trigger the popup's extensionUnloaded event --- ext/fg/js/popup.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'ext/fg/js/popup.js') diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 4f2de4f2..35e66044 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -83,6 +83,7 @@ class Popup { this._frame.addEventListener('mousedown', (e) => e.stopPropagation()); this._frame.addEventListener('scroll', (e) => e.stopPropagation()); this._frame.addEventListener('load', this._onFrameLoad.bind(this)); + yomichan.on('extensionUnloaded', this._onExtensionUnloaded.bind(this)); } isProxy() { @@ -149,8 +150,12 @@ class Popup { this._invokeApi('setCustomCss', {css}); } - clearAutoPlayTimer() { - this._invokeApi('clearAutoPlayTimer'); + async clearAutoPlayTimer() { + try { + await this._invokeApi('clearAutoPlayTimer'); + } catch (e) { + // NOP + } } setContentScale(scale) { @@ -447,6 +452,18 @@ class Popup { return await api.crossFrame.invoke(this._frameClient.frameId, 'popupMessage', message); } + _invokeWindowApi(action, params={}) { + const contentWindow = this._frame.contentWindow; + if (this._frameClient === null || !this._frameClient.isConnected() || contentWindow === null) { return; } + + const message = this._frameClient.createMessage({action, params}); + contentWindow.postMessage(message, this._targetOrigin); + } + + _onExtensionUnloaded() { + this._invokeWindowApi('extensionUnloaded'); + } + _getFrameParentElement() { const defaultParent = document.body; const fullscreenElement = DOM.getFullscreenElement(); @@ -636,15 +653,4 @@ class Popup { bottom: window.innerHeight }; } - - static isFrameAboutBlank(frame) { - try { - const contentDocument = frame.contentDocument; - if (contentDocument === null) { return false; } - const url = contentDocument.location.href; - return /^about:blank(?:[#?]|$)/.test(url); - } catch (e) { - return false; - } - } } -- cgit v1.2.3