summaryrefslogtreecommitdiff
path: root/ext/fg/js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js')
-rw-r--r--ext/fg/js/content-script-main.js42
1 files changed, 26 insertions, 16 deletions
diff --git a/ext/fg/js/content-script-main.js b/ext/fg/js/content-script-main.js
index b057ae3d..cebda2d7 100644
--- a/ext/fg/js/content-script-main.js
+++ b/ext/fg/js/content-script-main.js
@@ -24,6 +24,19 @@
* api
*/
+async function createPopupFactory() {
+ const {frameId} = await api.frameInformationGet();
+ if (typeof frameId !== 'number') {
+ const error = new Error('Failed to get frameId');
+ yomichan.logError(error);
+ throw error;
+ }
+
+ const popupFactory = new PopupFactory(frameId);
+ await popupFactory.prepare();
+ return popupFactory;
+}
+
async function createIframePopupProxy(frameOffsetForwarder, setDisabled) {
const rootPopupInformationPromise = yomichan.getTemporaryListenerResult(
chrome.runtime.onMessage,
@@ -44,20 +57,8 @@ async function createIframePopupProxy(frameOffsetForwarder, setDisabled) {
return popup;
}
-async function getOrCreatePopup(depth) {
- const {frameId} = await api.frameInformationGet();
- if (typeof frameId !== 'number') {
- const error = new Error('Failed to get frameId');
- yomichan.logError(error);
- throw error;
- }
-
- const popupFactory = new PopupFactory(frameId);
- await popupFactory.prepare();
-
- const popup = popupFactory.getOrCreatePopup(null, null, depth);
-
- return popup;
+async function getOrCreatePopup(depth, popupFactory) {
+ return popupFactory.getOrCreatePopup(null, null, depth);
}
async function createPopupProxy(depth, id, parentFrameId) {
@@ -85,6 +86,7 @@ async function createPopupProxy(depth, id, parentFrameId) {
let frontend = null;
let frontendPreparePromise = null;
let frameOffsetForwarder = null;
+ let popupFactoryPromise = null;
let iframePopupsInRootFrameAvailable = true;
@@ -124,8 +126,16 @@ async function createPopupProxy(depth, id, parentFrameId) {
popup = popups.proxy || await createPopupProxy(depth, id, parentFrameId);
popups.proxy = popup;
} else {
- popup = popups.normal || await getOrCreatePopup(depth);
- popups.normal = popup;
+ popup = popups.normal;
+ if (!popup) {
+ if (popupFactoryPromise === null) {
+ popupFactoryPromise = createPopupFactory();
+ }
+ const popupFactory = await popupFactoryPromise;
+ const popupNormal = await getOrCreatePopup(depth, popupFactory);
+ popups.normal = popupNormal;
+ popup = popupNormal;
+ }
}
if (frontend === null) {