From 7f56a08f3ba5407e6c8cdec12dc59aa71aa06d03 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 17 Jun 2018 21:42:52 +0900 Subject: Use async/await on content script --- src/content/components/common/index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/content/components/common/index.js') diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js index 9b7b083..6437011 100644 --- a/src/content/components/common/index.js +++ b/src/content/components/common/index.js @@ -44,15 +44,16 @@ export default class Common { } } - reloadSettings() { - browser.runtime.sendMessage({ - type: messages.SETTINGS_QUERY, - }).then((settings) => { + async reloadSettings() { + try { + let settings = await browser.runtime.sendMessage({ + type: messages.SETTINGS_QUERY, + }); this.store.dispatch(settingActions.set(settings)); - }).catch((e) => { + } catch (e) { // Sometime sendMessage fails when background script is not ready. console.warn(e); setTimeout(() => this.reloadSettings(), 500); - }); + } } } -- cgit v1.2.3