chrome 在 Microsoft Edge 扩展中未定义

chrome is undefined in microsoft edge extension

美好的一天,我已经写了一个扩展,我希望在每个 platform/browser 上 运行。它在 chrome 和 firefox 上运行良好,但在 windows 10 上使用 ie-edge 时出现错误。它一直抛出 chrome 未定义。有没有办法让它定义为我在整个扩展中一直使用的。

谢谢

export default {
  browserAction: {
    onClicked: chrome.browserAction !== undefined ? chrome.browserAction.onClicked : undefined,
    setBadgeText: chrome.browserAction !== undefined ? chrome.browserAction.setBadgeText : undefined,
    setTitle: chrome.browserAction !== undefined ? chrome.browserAction.setTitle : undefined,
    setIcon: chrome.browserAction !== undefined ? chrome.browserAction.setIcon : undefined,
  },
  extension: {
    getURL: chrome.extension !== undefined ? chrome.extension.getURL : undefined,
  },
  runtime: {
    onMessage: chrome.runtime.onMessage || browser.runtime.onMessage,
    reload: chrome.runtime.reload,
    sendMessage: chrome.runtime.sendMessage,
  },
  tabs: {
    create: chrome.tabs !== undefined ? chrome.tabs.create : undefined,
    executeScript: chrome.tabs !== undefined ? chrome.tabs.executeScript : undefined,
    get: chrome.tabs !== undefined ? chrome.tabs.get : undefined,
    onActivated: chrome.tabs !== undefined ? chrome.tabs.onActivated : undefined,
    onUpdated: chrome.tabs !== undefined ? chrome.tabs.onUpdated : undefined,
    query: chrome.tabs !== undefined ? chrome.tabs.query : undefined,
    remove: chrome.tabs !== undefined ? chrome.tabs.remove : undefined,
    sendMessage: chrome.tabs !== undefined ? chrome.tabs.sendMessage : undefined,
  },
  webRequest: {
    onBeforeRedirect: chrome.tabs !== undefined ? chrome.webRequest.onBeforeRedirect : undefined,
  },
};

只需将 Microsoft Edge Extension Toolkit. Here is how you can load the extension 安装到 toolkit 即可修复该错误。