1

i'm trying to port Chrome Extension on Nightly(for now) using webextension module , but , when i'm trying to do require("sdk/tabs");

var tabs = require("sdk/tabs");

tabs.on("ready",function(tabs) {
  if (tabs && tabs.url && tabs.url.match(driveURLpattern) || tabs.url.match(docsURLpattern)) {
    currentTabId = tabs.id;
    return authentication();
  }

});

Console: ReferenceError: require is not defined

But it doesn't work...How can i define it ?

UPDATE: Original code for Chrome is:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status === 'complete') {
  if (tab && tab.url && tab.url.match(driveURLpattern) || tab.url.match(docsURLpattern)) {
    currentTabId = tab.id;
    return authentication();
  }
}

});

Thanks in advance !

eKivOx

EDIT : SOLUTION WAS FOUND. THANK YOU

The solution is , require isn't in WebExtensions, we can't do like the SDK-addons , so i've check compatibilities of ChromeAPi and i saw chrome.tabs.onUpdated() is compatible !Cya

  • I mean, you're using jpm to create the firefox extension - you've initialised using `jpm init` and testing using `jpm run` etc – Jaromanda X Oct 19 '15 at 13:48
  • I'm not using the SDK-addon, i've a code for Chrome and i want to change it for Firefox – Arthur Cretté Oct 19 '15 at 13:49
  • 1
    `i've a code for Chrome and i want to change it for Firefox` - my mistake, I thought you were trying to create an extension – Jaromanda X Oct 19 '15 at 13:52
  • I want to do like this : https://github.com/mdn/webextensions-examples/ – Arthur Cretté Oct 19 '15 at 13:52
  • you've read https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Porting_from_Google_Chrome – Jaromanda X Oct 19 '15 at 13:54
  • Yes but , Extension need few change , see update post – Arthur Cretté Oct 19 '15 at 13:55
  • I honestly can't keep up with firefox. I thought JPM was needed, but there's no mention of it anywhere in that page ... I give up :p – Jaromanda X Oct 19 '15 at 13:56
  • I don't know how can i do that...Maybe require is not compatible for now.. :( – Arthur Cretté Oct 19 '15 at 13:58
  • the only incompatibilites with chrome are supposedly here - https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Chrome_incompatibilities – Jaromanda X Oct 19 '15 at 13:59
  • Yes it's for that , i'm using Chrome.tabs.onUpdate , but not compatible for now , so i've change with tabs.on, like the example but , it doesn't work :( – Arthur Cretté Oct 19 '15 at 14:05
  • 2
    If you found a solution that actually addresses this specific question then post an answer and accept it. Please do not just edit the question to say that you solved it. Self answered questions are encouraged when you have found a solution to a particular question. Note that the answer should directly address the specific question you asked, not necessarily a solution that addresses your real need which underlies why you asked the question (these appear to be two separate things in this instance). – Makyen Oct 23 '15 at 16:25
  • Please share your found solution – Noitidart Oct 29 '15 at 22:42

1 Answers1

1

require is used in context of CommonJS modules. It imports the methods exported by library modules. You cannot port your chrome extension to FF-addon as is. You need to create a new Firefox extension using JPM, and within the add-on script, use require

HTH

Nandu
  • 808
  • 7
  • 10
  • Hello , Thank you for answered , I found a solution , i can't require in WebExtension , so i hope many Chrome functions will be available this year ! Thank – Arthur Cretté Oct 21 '15 at 08:24