aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2020-04-12 19:17:50 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2020-04-12 19:17:50 +0300
commit362ac84e6c6a0a4c2353232a5c44e1b2157de44d (patch)
treea49d7d1ac6d41373c19fb85758a904b1b6288ba4
parente627ab2537d6aee5323cf03e594be472db1a1881 (diff)
prevent spawning multiple FrameOffsetForwarders
-rw-r--r--ext/fg/js/frontend-initialize.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/ext/fg/js/frontend-initialize.js b/ext/fg/js/frontend-initialize.js
index 2c80c541..2b942258 100644
--- a/ext/fg/js/frontend-initialize.js
+++ b/ext/fg/js/frontend-initialize.js
@@ -24,7 +24,7 @@
* apiOptionsGet
*/
-async function createIframePopupProxy(url) {
+async function createIframePopupProxy(url, frameOffsetForwarder) {
const rootPopupInformationPromise = yomichan.getTemporaryListenerResult(
chrome.runtime.onMessage,
({action, params}, {resolve}) => {
@@ -36,8 +36,6 @@ async function createIframePopupProxy(url) {
apiBroadcastTab('rootPopupRequestInformationBroadcast');
const {popupId, frameId} = await rootPopupInformationPromise;
- const frameOffsetForwarder = new FrameOffsetForwarder();
- frameOffsetForwarder.start();
const getFrameOffset = frameOffsetForwarder.getOffset.bind(frameOffsetForwarder);
const popup = new PopupProxy(popupId, 0, null, frameId, url, getFrameOffset);
@@ -47,9 +45,6 @@ async function createIframePopupProxy(url) {
}
async function getOrCreatePopup(depth) {
- const frameOffsetForwarder = new FrameOffsetForwarder();
- frameOffsetForwarder.start();
-
const popupHost = new PopupProxyHost();
await popupHost.prepare();
@@ -81,14 +76,20 @@ async function main() {
let frontend = null;
let frontendPreparePromise = null;
+ let frameOffsetForwarder = null;
const applyOptions = async () => {
const optionsContext = {depth: isSearchPage ? 0 : depth, url};
const options = await apiOptionsGet(optionsContext);
+ if (!proxy && frameOffsetForwarder === null) {
+ frameOffsetForwarder = new FrameOffsetForwarder();
+ frameOffsetForwarder.start();
+ }
+
let popup;
if (isIframe && options.general.showIframePopupsInRootFrame) {
- popup = popups.iframe || await createIframePopupProxy(url);
+ popup = popups.iframe || await createIframePopupProxy(url, frameOffsetForwarder);
popups.iframe = popup;
} else if (proxy) {
popup = popups.proxy || await createPopupProxy(depth, id, parentFrameId, url);