Prahlad Yeri
Prahlad Yeri

Reputation: 3663

Userscript turned Firefox-addon is not running in browser

I'm new to addon development. Here is the simple user-script that I'm trying to convert into a firefox-addon. And this is just a simple private addon I'm going to use, not for AMO or something. The reason I'm converting this to an addon in first place is that Firefox for Android doesn't support the greasemonkey extension yet.

So, I referred to Wladimir Palant's answer here and went about building my addon by referring to mozilla docs. Here is my folder structure which I created my using jpm init:

--data>
    - redditplus.js //my userscript file. 
--index.js //main entry point
--package.json
--README.md

Here are the contents of index.js, the main entry point:

var data = require("self").data;
var pageMod = require("page-mod");

pageMod.PageMod({
  include: "*.reddit.com/*",
  contentScriptFile: data.url("redditplus.js"),
  contentScriptWhen: 'start'
});

I then go about building my addon like this:

jpm xpi

But when I install the compiled @redditplus-0.0.1.xpi addon in firefox, it doesn't work! The userscript is supposed to highlight any unread reddit comments or at least write some logs to console, but it is doing nothing. What am I missing here?

Upvotes: 0

Views: 187

Answers (1)

the8472
the8472

Reputation: 43117

The userscript has the following clause:

// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js

Which means it needs jquery to work.

You need to include the appropriate jquery file in your addon and pass it like this:

contentScriptFile: [data.url("jquery.js"), data.url("redditplus.js")]

The userscript is supposed to highlight any unread reddit comments or at least write some logs to console

To get log messages from SDK addons you need to set the following in about:config

extensions.sdk.console.logLevel = info

And open the browser console (ctrl+shift+j) instead of the tab's devtools console.

Another thing: Since the default for userscripts is @run-at document-end using contentScriptWhen: 'start' will probably break the script.

Upvotes: 1

Related Questions