1

Good day, I've written an extension which I would like run on every platform/browser. It works fine with chrome and firefox but just got error with ie-edge on windows 10. It keeps throwing chrome is not defined. Is there a way to make it define as I've been using through out my extension.

Thanks

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,
  },
};
Basheer Kharoti
  • 4,202
  • 5
  • 24
  • 50
  • @wOxxOm There isn't such error other then chrome is not defined – Basheer Kharoti Dec 14 '17 at 05:14
  • `For Microsoft Edge, all extension APIs are under the browser namespace, e.g. browser.browserAction.disable().` Use [their toolkit](https://learn.microsoft.com/en-us/microsoft-edge/extensions/guides/porting-chrome-extensions), it adds the necessary polyfills. – wOxxOm Dec 14 '17 at 05:19
  • @wOxxOm I've tried `console.log(browser.tabs)` and got undefined in `contentscript.js` – Basheer Kharoti Dec 14 '17 at 05:21
  • tabs API is [not available in a content script](https://developer.chrome.com/extensions/tabs) just like it's not in Chrome. – wOxxOm Dec 14 '17 at 05:31
  • @wOxxOm Thank you for your help but I've declared that and I got `Object doesn't support property or method 'lob'` – Basheer Kharoti Dec 14 '17 at 05:38
  • I'm afraid you'll have to use the most basic debugging method: remove/comment the code in halfs until it works, then uncomment back and find what's failing. – wOxxOm Dec 14 '17 at 05:45
  • And if I wasn't clear enough, you can't use `tabs` API in a content script. – wOxxOm Dec 14 '17 at 05:46
  • @wOxxOm I've found some similar docs which doesn't throw any more error regarding chrome but there is still some error regarding pollyfill.js. Here's the link https://learn.microsoft.com/en-us/microsoft-edge/extensions/guides/porting-chrome-extensions – Basheer Kharoti Dec 14 '17 at 05:49

1 Answers1

0

The error could be fixed by simply installing Microsoft Edge Extension Toolkit. Here is how you can load the extension into toolkit .

Basheer Kharoti
  • 4,202
  • 5
  • 24
  • 50