From 362ac84e6c6a0a4c2353232a5c44e1b2157de44d Mon Sep 17 00:00:00 2001 From: siikamiika Date: Sun, 12 Apr 2020 19:17:50 +0300 Subject: [PATCH] prevent spawning multiple FrameOffsetForwarders --- ext/fg/js/frontend-initialize.js | 15 ++++++++------- 1 file 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);