aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/popup.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-07-18 14:15:36 -0400
committerGitHub <noreply@github.com>2020-07-18 14:15:36 -0400
commitdac33e696145ad3c2cfe076a7fadc82c05732102 (patch)
tree06dff8bd7dd2d8ebad5a025cf71e2910b2af80d4 /ext/fg/js/popup.js
parentf9c76efea00ff62021119c4d0fcf414e8988be1d (diff)
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
Diffstat (limited to 'ext/fg/js/popup.js')
-rw-r--r--ext/fg/js/popup.js32
1 files changed, 19 insertions, 13 deletions
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;
- }
- }
}