/**
 * background.js
 */

import {
  throwErr,
} from "./common.js";
import {
  getAllStorage, setStorage,
} from "./browser.js";
import {
  handleCmd, handleDisconnectedHost, handleMsg, handlePort, host,
  onTabActivated, onTabRemoved, onTabUpdated, onWindowFocusChanged,
  onWindowRemoved, openOptionsPage, postContextMenuData, setDefaultIcon,
  setVars, syncUI, toggleBadge,
} from "./main.js";
import fileExtData from "./file-ext.js";
import liveEditData from "./live-edit.js";
import nsUriData from "./ns-uri.js";

/* api */
const {
  browserAction, commands, runtime, storage, tabs, windows,
} = browser;
const menus = browser.menus || browser.contextMenus;

/* constants */
import {
  FILE_EXT, LIVE_EDIT, NS_URI,
} from "./constant.js";

/* listeners */
browserAction.onClicked.addListener(() => openOptionsPage().catch(throwErr));
commands.onCommand.addListener(cmd => handleCmd(cmd).catch(throwErr));
menus.onClicked.addListener((info, tab) =>
  postContextMenuData(info, tab).catch(throwErr),
);
host.onDisconnect.addListener(port =>
  handleDisconnectedHost(port).then(toggleBadge).catch(throwErr),
);
host.onMessage.addListener(msg => handleMsg(msg).catch(throwErr));
runtime.onConnect.addListener(port => handlePort(port).catch(throwErr));
runtime.onMessage.addListener((msg, sender) =>
  handleMsg(msg, sender).catch(throwErr),
);
storage.onChanged.addListener(data =>
  setVars(data).then(syncUI).catch(throwErr),
);
tabs.onActivated.addListener(info => onTabActivated(info).catch(throwErr));
tabs.onUpdated.addListener((id, info, tab) =>
  onTabUpdated(id, info, tab).catch(throwErr),
);
tabs.onRemoved.addListener((id, info) =>
  onTabRemoved(id, info).catch(throwErr),
);
windows.onFocusChanged.addListener(windowId =>
  onWindowFocusChanged(windowId).catch(throwErr),
);
windows.onRemoved.addListener(windowId =>
  onWindowRemoved(windowId).catch(throwErr),
);

/* startup */
document.addEventListener("DOMContentLoaded", () => Promise.all([
  setDefaultIcon().then(getAllStorage).then(setVars).then(syncUI),
  setStorage({[NS_URI]: nsUriData}),
  setStorage({[FILE_EXT]: fileExtData}),
  setStorage({[LIVE_EDIT]: liveEditData}),
]).catch(throwErr));

@@ -908,104 +908,8 @@
 ));%0A
-menus.onClicked.addListener((info, tab) =%3E%0A  postContextMenuData(info, tab).catch(throwErr),%0A);%0A
 host
@@ -1070,32 +1070,128 @@
 tch(throwErr));%0A
+menus.onClicked.addListener((info, tab) =%3E%0A  postContextMenuData(info, tab).catch(throwErr),%0A);%0A
 runtime.onConnec

Update background.js