-
Notifications
You must be signed in to change notification settings - Fork 223
Conversation
There should probably be a forced settings update when using the root frame popup after using it from an iframe, but I haven't investigated it yet |
ext/fg/js/popup-nested.js
Outdated
let popupNestedInitialized = false; | ||
|
||
async function popupNestedInitialize(id, depth, parentFrameId, url) { | ||
if (popupNestedInitialized) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think popupNestedInitialized
is necessary anymore. Please remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's called from float.js
, but I can't think of cases when it would actually be called multiple times except maybe reloading the extension, and this check wouldn't help with that. Maybe there should be a check similar to the one in search-frontend.js
const node = document.querySelector(`script[src='${src}']`);
if (node !== null) { continue; }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that prepare should only be called once due to the _prepareInvoked
guard, so that should handle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ext/fg/js/frontend-initialize.js
Outdated
|
||
const isIframe = !proxy && (window !== window.parent); | ||
|
||
const initEventDispatcher = new EventDispatcher(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of initEventDispatcher
can probably be removed by some simplification.
initEventDispatcher
is only used by frontend
, which is only instantiated once. Add a setPopup
method on it for popupChange
, and setDisabledOverride
can probably be handled in a similar way, or by setting the popup to null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not set popup to null
because then I'd have to potentially handle nulls all the places where popup is used.
ext/mixed/js/text-scanner.js
Outdated
@@ -23,11 +23,13 @@ | |||
*/ | |||
|
|||
class TextScanner { | |||
constructor(node, ignoreElements, ignorePoints) { | |||
constructor(node, ignoreElements, ignorePoints, canEnable=null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than adding canEnable
, might be better to add it as an argument to setEnabled
. setEnabled
is only called from TextScanner.setOptions
, which is called from the subclasses of TextScanner
(i.e. Frontend
).
Meaning you can just pass this.popup.depth <= this.options.scanning.popupNestingMaxDepth && !this._disabledOverride
here:
yomichan/ext/fg/js/frontend.js
Line 147 in 791c51f
this.setOptions(await apiOptionsGet(this.getOptionsContext())); |
And true
here (or default value):
yomichan/ext/bg/js/search-query-parser.js
Line 109 in 791c51f
super.setOptions(options); |
This should give better control over when the object is enabled/disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like something's up with the CI, none of the tests go through |
Re-running it manually seems to have worked. ¯\_(ツ)_/¯ |
98d7e09
to
e6078ce
Compare
Actually, the settings should be the same regardless of the iframe proxy because the context is the same there with the current profile conditions. If a refresh is needed, something like this could be done: diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 20bfc638..df038e24 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -247,13 +247,20 @@ class Frontend extends TextScanner {
}
_showPopupContent(textSource, type=null, details=null) {
- this._lastShowPromise = this.popup.showContent(
- textSource.getRect(),
- textSource.getWritingMode(),
- type,
- details
+ let promise = this._lastShowPromise;
+ if (!this.popup.isProxy() && this.popup.usedByProxy()) {
+ this.popup.setUsedByProxy(false);
+ promise = promise.then(() => this.popup.setOptions(this.options));
+ }
+
+ this._lastShowPromise = promise.then(
+ () => this.popup.showContent(
+ textSource.getRect(),
+ textSource.getWritingMode(),
+ type,
+ details
+ )
);
- return this._lastShowPromise;
}
_updateContentScale() {
diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js
index 958462ff..2aa0e523 100644
--- a/ext/fg/js/popup-proxy-host.js
+++ b/ext/fg/js/popup-proxy-host.js
@@ -158,6 +158,7 @@ class PopupProxyHost {
if (typeof popup === 'undefined') {
throw new Error(`Invalid popup ID ${id}`);
}
+ popup.setUsedByProxy(true);
return popup;
}
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 42f08afa..4118368d 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -36,6 +36,7 @@ class Popup {
this._containerSizeContentScale = null;
this._targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, '');
this._messageToken = null;
+ this._usedByProxy = false;
this._container = document.createElement('iframe');
this._container.className = 'yomichan-float';
@@ -81,6 +82,14 @@ class Popup {
return false;
}
+ usedByProxy() {
+ return this._usedByProxy;
+ }
+
+ setUsedByProxy(used) {
+ this._usedByProxy = used;
+ }
+
async setOptions(options) {
this._options = options;
this.updateTheme(); |
It's a bit ambiguous what should be done with the This was broken when merging #417, but I've addressed the issue in b0d94e8. I can change it to |
ext/fg/js/frontend-initialize.js
Outdated
if (action === 'rootPopupInformation') { | ||
resolve(params); | ||
} | ||
const {id, depth=0, parentFrameId, url=window.top.location.href, proxy=false, isSearchPage=false} = data; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window.top.location.href
can have an exception. I tested manually on https://dic.nicovideo.jp/'s twitter widget and get the following error when trying to read it from its context:
Blocked a frame with origin "https://platform.twitter.com" from accessing a cross-origin frame.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder what's going to happen with the line below:
const isIframe = !proxy && (window !== window.parent);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested and that doesn't throw an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me.
ext/fg/js/frontend-initialize.js
Outdated
} | ||
|
||
async function getOrCreatePopup(depth) { | ||
const frameOffsetForwarder = new FrameOffsetForwarder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two FrameOffsetForwarder instances can exist at the same time this way; one from createIframePopupProxy
and one from getOrCreatePopup
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b80fd00
to
e627ab2
Compare
Noticed an issue:
Appears to have something to do with the iframes, since it doesn't occur on documents without iframes. |
Another issue I noticed, which may be a timing issue. Not as critical, but not sure how complex this would be to fix.
The options will use the old value of For testing, on line 290 I added: console.log('_canEnable', this.options, this.popup.depth, '<=', this.options !== null ? this.options.scanning.popupNestingMaxDepth : null, this._disabledOverride); Logged this:
|
This happens when https://github.com/FooSoft/yomichan/pull/439/files#diff-c0a35793e5728d9d3e4b1301d23a4c3bR113-R115 is run because |
Caused by calling |
Fixes #431