From e6347a94e7ff0b7a5c1db7e6f83f50d93c2d4545 Mon Sep 17 00:00:00 2001 From: siikamiika Date: Mon, 2 Mar 2020 23:26:55 +0200 Subject: prepare Backend for browser_action --- ext/bg/js/backend.js | 5 +++++ ext/bg/js/context.js | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js index be43ecf6..14b0aff1 100644 --- a/ext/bg/js/backend.js +++ b/ext/bg/js/backend.js @@ -278,6 +278,11 @@ class Backend { // Message handlers async _onApiYomichanCoreReady(_params, sender) { + // tab ID isn't set in background (e.g. browser_action) + if (typeof sender.tab === 'undefined') { + return chrome.runtime.sendMessage({action: 'backendPrepared'}); + } + const tabId = sender.tab.id; return new Promise((resolve) => { chrome.tabs.sendMessage(tabId, {action: 'backendPrepared'}, resolve); diff --git a/ext/bg/js/context.js b/ext/bg/js/context.js index bec964fb..1095c7e0 100644 --- a/ext/bg/js/context.js +++ b/ext/bg/js/context.js @@ -48,7 +48,9 @@ function setupButtonEvents(selector, command, url) { } } -window.addEventListener('DOMContentLoaded', () => { +window.addEventListener('DOMContentLoaded', async () => { + await yomichan.prepare(); + showExtensionInfo(); apiGetEnvironmentInfo().then(({browser}) => { -- cgit v1.2.3