Communicate between main.js and page script, page is loaded by windowUtils.open

254 views
Skip to first unread message

Giuseppe Piscopo

unread,
Nov 21, 2014, 4:24:33 AM11/21/14
to mozilla-la...@googlegroups.com
Hello all

I'm giving the full context at the end, but here is the main issue: 
I'm looking on how to allow a page script to communicate with add-on main.js, when the page (with its script) is found in a HTML document in data directory and it gets loaded in main.js by means of require("sdk/window/utils").open().

The full context:

I'm creating a restartless Thunderbird (!) add-on with add-on SDK, cfx, and so on: yes, it does not seem to be really supported, but here and there documentation says it can work, then of course other bits don't. Up to now I was able to build/run/package the add-on, interact with Compose window send events, to open a window from a given HTML document, to run jQuery and AngularJS in that HTML.
Now I'm looking on how to call back something in main.js from page script. I've been through the docs about postMessage, port, custom DOM event, pageWorker, content scripts, exportFunction, but apparently none of those techniques seems to work. Of course I've also searched in this forum.

For what I can see: many high-level SDK modules are not available to Thunderbird add-ons. Most of the times I tried to require page-mod or others the seems more like "utils" (ie not UI elements), I end up with the error that tabs module is required, and that is not supported in TB, only FF and Fennec.
So I found no way to load an HTML and attach a content script to that, and the only way I found to load an HTML was windowUtils.open, that offers no contentScript or attach option.

So I'm kinda stuck now.

Is there a way to require some helper high/low level SDK module that allows to attach content script to HTML document? Or is there another way to directly put in contact main.js with page script, without the need for content script?

Thanks all for your time

Frédéric WANG

unread,
Nov 21, 2014, 4:49:49 AM11/21/14
to mozilla-la...@googlegroups.com
Hi Giuseppe,

That does not quite address your particular problem, but FYI I've recently successfully enabled some SDK modules for SeaMonkey and I've been trying to do the same with Thunderbird:

https://bugzilla.mozilla.org/show_bug.cgi?id=1100644

I've been working with Nightly build & the git addon-sdk repository. The command I found to force the use of a custom addon-sdk in Thunderbird is

cfx xpi --no-strip-xpi --force-use-bundled-sdk

However, I've not been able to make the simplest add-on work, so I suspect Thunderbird is not supported (addon-sdk devs might know the status better) but I need to debug that more carefully. If you are interested in making addon-sdk compatible with Thunderbird, I'd appreciate if you could help me with  bug 1100644.

From what I did in https://bugzilla.mozilla.org/show_bug.cgi?id=1023661, many modules won't easily be compatible with Thunderbird/SeaMonkey (comm-central). However, the simple communication between the content and main script should be doable, since I've been able to make many of my add-ons compatible with SeaMonkey. In general, anything that does not involve too complex UIs seem to work with SeaMonkey.
--
You received this message because you are subscribed to the Google Groups "mozilla-labs-jetpack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozilla-labs-jet...@googlegroups.com.
To post to this group, send email to mozilla-la...@googlegroups.com.
Visit this group at http://groups.google.com/group/mozilla-labs-jetpack.
For more options, visit https://groups.google.com/d/optout.


-- 
Frédéric Wang
maths-informatique-jeux.com/blog/frederic

signature.asc

Giuseppe Piscopo

unread,
Nov 21, 2014, 5:16:24 AM11/21/14
to mozilla-la...@googlegroups.com, fred...@free.fr
Hello Frédéric, thanks for your quick reply.
I'll have a look at the link you posted, as I understand this is somehow "collateral" to my issue... anyway.

Just to be safe on common understanding: when you says "simple communication between the content and main script", I'm looking for communication between page script (e.g. from a <script> tag in HTML document) and main script, as at the moment I found no way to attach a content script to the HTML nor the nsIDOMWindow. Do you mean the same?

Cheers
To unsubscribe from this group and stop receiving emails from it, send an email to mozilla-labs-jetpack+unsub...@googlegroups.com.

To post to this group, send email to mozilla-la...@googlegroups.com.
Visit this group at http://groups.google.com/group/mozilla-labs-jetpack.
For more options, visit https://groups.google.com/d/optout.

Frédéric WANG

unread,
Nov 21, 2014, 5:42:06 AM11/21/14
to Giuseppe Piscopo, mozilla-la...@googlegroups.com
Le 21/11/2014 11:16, Giuseppe Piscopo a écrit :
Just to be safe on common understanding: when you says "simple communication between the content and main script", I'm looking for communication between page script (e.g. from a <script> tag in HTML document) and main script, as at the moment I found no way to attach a content script to the HTML nor the nsIDOMWindow. Do you mean the same?
The content script can do whatever on the HTML page it is attached to (including communicating with an existing "page script", whatever you mean by that) and can communicate with the main script. The main script has "chrome privilege" that is has access to private Gecko APIs. I don't think you can communicate directly from the main script to a "page script".

I have some very basic add-ons showing this scheme main script <=> content script:

https://github.com/fred-wang/Mathzilla/tree/master/mathml-copy
https://github.com/fred-wang/Mathzilla/tree/master/mathjax-native-mathml (this one modifies the MathJax.js "page script", but I don't know if that's what you meant)
https://github.com/fred-wang/Mathzilla/tree/master/mathml-zoom
https://github.com/fred-wang/Mathzilla/tree/master/mathml-fontsettings
https://addons.mozilla.org/en-US/firefox/collections/fred_wang/mathzilla/

and I've been able to make them work with SeaMonkey by enabling more modules, so I'd expect they could work on Thunderbird too. But as I said, at the moment I failed to make any add-on work with Thunderbird. Have you been able to make a simple add-on for Thunderbird with the add-on sdk (e.g. just logging in the main script)?

BTW, there is another issue: the add-on sdk does not generate compatibility instructions in install.rdf for SeaMonkey/Thunderbird, so add-ons will fail to install.
-- 
Frédéric Wang
maths-informatique-jeux.com/blog/frederic

signature.asc

Adrian Aichner

unread,
Nov 21, 2014, 5:50:40 AM11/21/14
to mozilla-la...@googlegroups.com
I think jpm would do that by means of the engines field in package.json

Have you tried building with
jpm xpi
as well?

There are some transition issues from cfx to jpm to be aware of:

https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/cfx_to_jpm

I am also interested in making some SDK-based add-ons work in Thunderbird.

Adrian

-- 
Frédéric Wang
maths-informatique-jeux.com/blog/frederic

--
You received this message because you are subscribed to the Google Groups "mozilla-labs-jetpack" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozilla-labs-jet...@googlegroups.com.

Frédéric WANG

unread,
Nov 21, 2014, 6:03:19 AM11/21/14
to mozilla-la...@googlegroups.com
Le 21/11/2014 11:50, Adrian Aichner a écrit :
I think jpm would do that by means of the engines field in package.json

Have you tried building with
jpm xpi
as well?

No, I haven't tried jpm yet, thanks for the info.
I saw the comment https://bugzilla.mozilla.org/show_bug.cgi?id=724276#c17 but the "engines" field didn't seem to work with cfx...

-- 
Frédéric Wang
maths-informatique-jeux.com/blog/frederic

signature.asc

Frédéric WANG

unread,
Nov 21, 2014, 6:50:38 AM11/21/14
to mozilla-la...@googlegroups.com
I commented on https://bugzilla.mozilla.org/show_bug.cgi?id=1100644, but
just to follow up here... I tried again and fixed a regression I
introduced while working on SeaMonkey compat. So I've been able to make
a simple add-on

var utils = require('sdk/window/utils');
utils.open();

work on Thunderbird. I'll do more testing this afternoon and see if we
can enable more modules for Thunderbird.

--
Frédéric Wang
maths-informatique-jeux.com/blog/frederic


signature.asc

Giuseppe Piscopo

unread,
Nov 21, 2014, 7:31:32 AM11/21/14
to mozilla-la...@googlegroups.com, fred...@free.fr
I just read these new posts and I doubt I was not clear, hope to do better now. Also, I'd be happy to avoid unnecessary work for everyone:

at the moment I'm already able:
  1. to create a restartless Thunderbird add-on by means of add-on SDK. 
    1. Both starting from v1.17 and from latest master branch
    2. In order to make that work for Thunderbird, I manually patch install.rdf to insert Thunderbird in final generated manifest
    3. In order to make that work on Windows, I had to fix what I think is a bug in a batch file
  2. to build and package add-on from command line with cfx xpi 
  3. to run add-on inside Thunderbird from command line with cfx run
  4. to run cfx test, although I don't remember with which results ... I kinda recall there where a lot of errors not due to my addon
  5. to split main script file in several custom modules, all having "chrome privileges"
  6. to interact with windowMediator, setup compose window event listeners, intercept Message Send events
  7. to open a HTML document (in data directory) with windowUtils.open()
  8. to execute javascript code found in the HTML document within <script> tags. 
    1. This kind of javascript is what I found, in other documents, dubbed as "page script", as opposed to "main script" and as opposed to "content script" attached to a page with things like pageMod and worker.
  9. to run jQuery and AngularJS code from the "page script" in HTML document
So, if somebody needs info on these, I'm more than happy to contribute.

Thanks all!

Giuseppe Piscopo

unread,
Nov 21, 2014, 7:46:45 AM11/21/14
to mozilla-la...@googlegroups.com, fred...@free.fr
About JPM: I read those docs days ago during the search, yet they do not seem to help in this context. 
Actually, things could go worse because documentation says that addons made with that are not supported yet by AMO, and because it looks to me that if thunderbird add-on SKD support is flaky, I can only wonder how things can go with brand new JPM. Please take these as "first look impressions" and correct me if I'm wrong.

Apart from JPM, I also think that if we're able to make some particular SDK module compatible with TB then we could move forward. Specifically, I think that pageMod, worker, or tabs might help if they could be made available to TB. Has anyone of them already made available for SeaMonkey?

Frédéric WANG

unread,
Nov 21, 2014, 7:56:17 AM11/21/14
to Giuseppe Piscopo, mozilla-la...@googlegroups.com
Le 21/11/2014 13:46, Giuseppe Piscopo a écrit :
> Apart from JPM, I also think that if we're able to make some
> particular SDK module compatible with TB then we could move forward.
> Specifically, I think that pageMod, worker, or tabs might help if they
> could be made available to TB. Has anyone of them already made
> available for SeaMonkey?
At least sdk/page-modare used in my mathml-zoom & mathml-fontsettings
addons:

https://github.com/fred-wang/Mathzilla/blob/master/mathml-zoom/lib/main.js
https://github.com/fred-wang/Mathzilla/blob/master/mathml-fontsettings/lib/main.js

and I verified that it works with the patches of bug 1023661.


signature.asc

Giuseppe Piscopo

unread,
Nov 21, 2014, 10:50:32 AM11/21/14
to mozilla-la...@googlegroups.com, piscopo....@gmail.com, fred...@free.fr
Thanks for references. As soon as I require page-mod with

const pageMod = require("sdk/page-mod");

I got twice this (usual to me) error:

console.error: tb-addon:
  Message: Error: Unsupported Application: The module sdk/tabs/tab currently supports only Firefox, Fennec.
  Stack:
    incompatibility@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:81:1
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:135:15
@resource://gre/modules/commonjs/sdk/tabs/helpers.js:15:17
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
@resource://gre/modules/commonjs/sdk/content/worker.js:22:29
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
@resource://gre/modules/commonjs/sdk/page-mod.js:17:20
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
tryWithPageMod@resource://tb-addon-123-at-jetpack/tb-addon/lib/dummy/dummyCommunication.js:72:19
setListener@resource://tb-addon-123-at-jetpack/tb-addon/lib/dummy/dummyCommunication.js:88:3
@resource://tb-addon-123-at-jetpack/tb-addon/lib/dummy/dummyWindowUtils.js:72:1
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
@resource://tb-addon-123-at-jetpack/tb-addon/lib/main.js:12:26
CuddlefishLoader/options<.load@resource://gre/modules/commonjs/sdk/loader/cuddlefish.js:129:18
run@resource://gre/modules/commonjs/sdk/addon/runner.js:172:19
startup/<@resource://gre/modules/commonjs/sdk/addon/runner.js:115:7
Handler.prototype.process@resource://gre/modules/Promise-backend.js:866:23
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise-backend.js:745:7

This happens also if I add "Thunderbird":"*" engine to any SDK module where SeaMonkey was added as well.

This has also bitten me in the past days. 
  1. Is there any way to figure out which module is pulling sdk/tabs/tab, and/or 
  2. Does anyone know if to make that compatible with TB is just a matter of setting engines?
TA

Frédéric WANG

unread,
Nov 21, 2014, 11:16:59 AM11/21/14
to Giuseppe Piscopo, mozilla-la...@googlegroups.com
Giuseppe:

As I see, addon-sdk 1.17 has the following in lib/sdk/tabs/tab.js

module.metadata = {
'stability': 'unstable',
'engines': {
'Firefox': '*',
'Fennec': '*'
}
};

so Thunderbird will be rejected. In the dev version, this is fixed:

https://github.com/mozilla/addon-sdk/blob/master/lib/sdk/tabs/tab.js#L6

However, note that by default cfx strips the sdk from the xpi and the
sdk bundled with Thunderbird is always used. That's why I used the command

cfx xpi --no-strip-xpi --force-use-bundled-sdk

IIUC, setting "engines" is really just to modify install.rdf and only
works with jpm.

I did more experiments with Thunderbird but the attempt was not very
successful:

https://bugzilla.mozilla.org/show_bug.cgi?id=1100644#c6

I suspect Thunderbird is even more far away from Firefox than SeaMonkey
is, and so will need more work than just declaring it in
module.metadata. I didn't try page-mod with Thunderbird.

--
Frédéric Wang
maths-informatique-jeux.com/blog/frederic


signature.asc

Giuseppe Piscopo

unread,
Nov 21, 2014, 11:36:39 AM11/21/14
to mozilla-la...@googlegroups.com, piscopo....@gmail.com, fred...@free.fr
Thanks for clarifying that. I'm trying with add-on SDK dev version as well. 
Just to know: when you pack the XPI (with the command you provided) how do you make that available into a (development) Thunderbird profile?
In my case, I had to rename it and copy it under profile extensions directory. Is there a quicker way?

Frédéric WANG

unread,
Nov 21, 2014, 11:42:46 AM11/21/14
to Giuseppe Piscopo, mozilla-la...@googlegroups.com
I'm opening the add-on menu with

tools => add-ons

and then I can do "install an add-on from a file" normally.

Le 21/11/2014 17:36, Giuseppe Piscopo a écrit :
> Thanks for clarifying that. I'm trying with add-on SDK dev version as
> well.
> Just to know: when you pack the XPI (with the command you provided)
> how do you make that available into a (development) Thunderbird profile?
> In my case, I had to rename it and copy it under profile extensions
> directory. Is there a quicker way?

--
Frédéric Wang
maths-informatique-jeux.com/blog/frederic


signature.asc

Giuseppe Piscopo

unread,
Nov 21, 2014, 12:00:03 PM11/21/14
to mozilla-la...@googlegroups.com, piscopo....@gmail.com, fred...@free.fr
Created a simple addon that requires page-mod. Packaged with --no-strip-xpi --force-use-bundled-sdk. Installed in TB 33. Apart from other informative messages on addon being installed, this is the main blurb coming out from TB error console (and also command prompt console):

1416589089139   addons.xpi      DEBUG   Calling bootstrap method startup on page-mod-addon-123@jetpack version 0.1
Bootstrap error: Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXPCComponents_Utils.import]
@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-...@jetpack.xpi!/bootstrap.js -> resource://page-mod-addon-123-at-jetpack/addon-sdk/lib/sdk/system/xul-app.js:11:17
loadSandbox@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-...@jetpack.xpi!/bootstrap.js:286:2
@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-...@jetpack.xpi!/bootstrap.js -> resource://page-mod-addon-123-at-jetpack/addon-sdk/lib/sdk/loader/cuddlefish.js:33:22
loadSandbox@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-...@jetpack.xpi!/bootstrap.js:286:2
startup@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-...@jetpack.xpi!/bootstrap.js:197:24
XPI_callBootstrapMethod@resource://gre/modules/addons/XPIProvider.jsm:4303:8
AI_startInstall/<@resource://gre/modules/addons/XPIProvider.jsm:5673:12
TaskImpl_run@resource://gre/modules/Task.jsm:330:40
Handler.prototype.process@resource://gre/modules/Promise.jsm -> resource://gre/modules/Promise-backend.js:866:22
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise.jsm -> resource://gre/modules/Promise-backend.js:745:6

Giuseppe Piscopo

unread,
Nov 21, 2014, 12:05:30 PM11/21/14
to mozilla-la...@googlegroups.com, piscopo....@gmail.com, fred...@free.fr
Uhm, actually that one comes out whether I require page-mod or not, so that must be something else. 
Anyway it looks like that's preventing my add-on to work, as I cannot even show a console log from main.js. This is my (non working) simple example:

main.js
'use strict';

const pageMod = require("sdk/page-mod");

console.log('******************* DONE *******************');

package.json
{
  "name": "page-mod-addon",
  "title": "page-mod-addon",
  "id": "page-mod-addon-123",
  "description": "Add-on to test page-mod in Thunderbird",
  "author": "Giuseppe Piscopo",
  "license": "MPL 2.0",
  "version": "0.1"
}


On Friday, November 21, 2014 6:00:03 PM UTC+1, Giuseppe Piscopo wrote:
Created a simple addon that requires page-mod. Packaged with --no-strip-xpi --force-use-bundled-sdk. Installed in TB 33. Apart from other informative messages on addon being installed, this is the main blurb coming out from TB error console (and also command prompt console):

1416589089139   addons.xpi      DEBUG   Calling bootstrap method startup on page-mod-addon-123@jetpack version 0.1
Bootstrap error: Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXPCComponents_Utils.import]
@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addo...@jetpack.xpi!/bootstrap.js -> resource://page-mod-addon-123-at-jetpack/addon-sdk/lib/sdk/system/xul-app.js:11:17
loadSandbox@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addo...@jetpack.xpi!/bootstrap.js:286:2
@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addo...@jetpack.xpi!/bootstrap.js -> resource://page-mod-addon-123-at-jetpack/addon-sdk/lib/sdk/loader/cuddlefish.js:33:22
loadSandbox@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addo...@jetpack.xpi!/bootstrap.js:286:2
startup@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addo...@jetpack.xpi!/bootstrap.js:197:24

Frédéric WANG

unread,
Nov 21, 2014, 12:13:21 PM11/21/14
to Giuseppe Piscopo, mozilla-la...@googlegroups.com
Did you take https://bugzilla.mozilla.org/attachment.cgi?id=8526697 that I mentioned earlier? Otherwise the dev version will raise js error on Thunderbird...

(also I believe cfx removes the logging from the final xpi)
signature.asc

Giuseppe Piscopo

unread,
Nov 21, 2014, 1:46:12 PM11/21/14
to mozilla-la...@googlegroups.com, piscopo....@gmail.com, fred...@free.fr
No, actually I didn't. Now I applied that change to sdk\window\utils.js, and this is the "main" message from TB console output when installing XPI:

1416594983324   addons.xpi      DEBUG   Calling bootstrap method startup on page-mod-addon-123@jetpack version 0.1
Bootstrap error: Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXPCComponents_Utils.import]
@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-...@jetpack.xpi!/bootstrap.js -> resource://page-mod-addon-123-at-jetpack/addon-sdk/lib/sdk/system/xul-app.js:11:17
loadSandbox@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-...@jetpack.xpi!/bootstrap.js:286:2
@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-...@jetpack.xpi!/bootstrap.js -> resource://page-mod-addon-123-at-jetpack/addon-sdk/lib/sdk/loader/cuddlefish.js:33:22
loadSandbox@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-...@jetpack.xpi!/bootstrap.js:286:2
startup@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-...@jetpack.xpi!/bootstrap.js:197:24
XPI_callBootstrapMethod@resource://gre/modules/addons/XPIProvider.jsm:4303:8
AI_startInstall/<@resource://gre/modules/addons/XPIProvider.jsm:5673:12
TaskImpl_run@resource://gre/modules/Task.jsm:330:40
Handler.prototype.process@resource://gre/modules/Promise.jsm -> resource://gre/modules/Promise-backend.js:866:22
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise.jsm -> resource://gre/modules/Promise-backend.js:745:6

which (as before) becomes a WARN with an exception:

1416594983494   addons.xpi      WARN    Exception running bootstrap method startup on page-mod-addon-123@jetpack: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXPCComponents_Utils.import]"  nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)"  location: "JS frame :: resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-...@jetpack.xpi!/bootstrap.js -> [...continue]

Just for completenes, both now and before, I got this errors when packaging XPI with cfx xpi --no-strip-xpi --force-use-bundled-sdk:

Warning: missing module: resource://gre/modules/Preferences.jsm
Warning: missing module: ../../framescript/FrameScriptManager.jsm



On Friday, November 21, 2014 6:13:21 PM UTC+1, Frédéric WANG wrote:
Did you take https://bugzilla.mozilla.org/attachment.cgi?id=8526697 that I mentioned earlier? Otherwise the dev version will raise js error on Thunderbird...

(also I believe cfx removes the logging from the final xpi)

Le 21/11/2014 18:05, Giuseppe Piscopo a écrit :
Uhm, actually that one comes out whether I require page-mod or not, so that must be something else. 
Anyway it looks like that's preventing my add-on to work, as I cannot even show a console log from main.js. This is my (non working) simple example:

main.js
'use strict';

const pageMod = require("sdk/page-mod");

console.log('******************* DONE *******************');

package.json
{
  "name": "page-mod-addon",
  "title": "page-mod-addon",
  "id": "page-mod-addon-123",
  "description": "Add-on to test page-mod in Thunderbird",
  "author": "Giuseppe Piscopo",
  "license": "MPL 2.0",
  "version": "0.1"
}


On Friday, November 21, 2014 6:00:03 PM UTC+1, Giuseppe Piscopo wrote:
Created a simple addon that requires page-mod. Packaged with --no-strip-xpi --force-use-bundled-sdk. Installed in TB 33. Apart from other informative messages on addon being installed, this is the main blurb coming out from TB error console (and also command prompt console):

1416589089139   addons.xpi      DEBUG   Calling bootstrap method startup on page-mod-addon-123@jetpack version 0.1
Bootstrap error: Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXPCComponents_Utils.import]
@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addon...@jetpack.xpi!/bootstrap.js -> resource://page-mod-addon-123-at-jetpack/addon-sdk/lib/sdk/system/xul-app.js:11:17
loadSandbox@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addon...@jetpack.xpi!/bootstrap.js:286:2
@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addon...@jetpack.xpi!/bootstrap.js -> resource://page-mod-addon-123-at-jetpack/addon-sdk/lib/sdk/loader/cuddlefish.js:33:22
loadSandbox@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addon...@jetpack.xpi!/bootstrap.js:286:2
startup@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addon...@jetpack.xpi!/bootstrap.js:197:24
XPI_callBootstrapMethod@resource://gre/modules/addons/XPIProvider.jsm:4303:8
AI_startInstall/<@resource://gre/modules/addons/XPIProvider.jsm:5673:12
TaskImpl_run@resource://gre/modules/Task.jsm:330:40
Handler.prototype.process@resource://gre/modules/Promise.jsm -> resource://gre/modules/Promise-backend.js:866:22
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise.jsm -> resource://gre/modules/Promise-backend.js:745:6



On Friday, November 21, 2014 5:42:46 PM UTC+1, Frédéric WANG wrote:
I'm opening the add-on menu with

tools => add-ons

and then I can do "install an add-on from a file" normally.

Le 21/11/2014 17:36, Giuseppe Piscopo a écrit :
> Thanks for clarifying that. I'm trying with add-on SDK dev version as
> well.
> Just to know: when you pack the XPI (with the command you provided)
> how do you make that available into a (development) Thunderbird profile?
> In my case, I had to rename it and copy it under profile extensions
> directory. Is there a quicker way?

--
Frédéric Wang
maths-informatique-jeux.com/blog/frederic


Giuseppe Piscopo

unread,
Nov 21, 2014, 2:01:30 PM11/21/14
to mozilla-la...@googlegroups.com, piscopo....@gmail.com, fred...@free.fr
Ok, probably the last two warnings at package time can be ignored: https://bugzilla.mozilla.org/show_bug.cgi?id=1084489


On Friday, November 21, 2014 7:46:12 PM UTC+1, Giuseppe Piscopo wrote:
No, actually I didn't. Now I applied that change to sdk\window\utils.js, and this is the "main" message from TB console output when installing XPI:

1416594983324   addons.xpi      DEBUG   Calling bootstrap method startup on page-mod-addon-123@jetpack version 0.1
Bootstrap error: Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXPCComponents_Utils.import]
@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addo...@jetpack.xpi!/bootstrap.js -> resource://page-mod-addon-123-at-jetpack/addon-sdk/lib/sdk/system/xul-app.js:11:17
loadSandbox@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addo...@jetpack.xpi!/bootstrap.js:286:2
@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addo...@jetpack.xpi!/bootstrap.js -> resource://page-mod-addon-123-at-jetpack/addon-sdk/lib/sdk/loader/cuddlefish.js:33:22
loadSandbox@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addo...@jetpack.xpi!/bootstrap.js:286:2
startup@resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addo...@jetpack.xpi!/bootstrap.js:197:24
XPI_callBootstrapMethod@resource://gre/modules/addons/XPIProvider.jsm:4303:8
AI_startInstall/<@resource://gre/modules/addons/XPIProvider.jsm:5673:12
TaskImpl_run@resource://gre/modules/Task.jsm:330:40
Handler.prototype.process@resource://gre/modules/Promise.jsm -> resource://gre/modules/Promise-backend.js:866:22
this.PromiseWalker.walkerLoop@resource://gre/modules/Promise.jsm -> resource://gre/modules/Promise-backend.js:745:6

which (as before) becomes a WARN with an exception:

1416594983494   addons.xpi      WARN    Exception running bootstrap method startup on page-mod-addon-123@jetpack: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXPCComponents_Utils.import]"  nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)"  location: "JS frame :: resource://gre/modules/addons/XPIProvider.jsm -> jar:file:///D:/WS/ThunderBird/Profiles/Thunderbird/qs1pt2h8.devTest/extensions/page-mod-addo...@jetpack.xpi!/bootstrap.js -> [...continue]

Giuseppe Piscopo

unread,
Nov 21, 2014, 3:21:49 PM11/21/14
to mozilla-la...@googlegroups.com, piscopo....@gmail.com, fred...@free.fr
I don't really get what that error is about... to my eyes it does not explicitly says what's wrong, cannot say if it's related to requiring page-mod or what, so I'm not even sure if I'm chasing ghosts.
In order to test addon with your change to sdk I have to package and install XPI inside TB. In this scenario that error shows up and I'm even more lost than before. I'm not sure if your change makes a difference for this case (please just tell me if I'm wrong), but if I switch back to just cfx-running the addon at least I can see the log, and I can see the error about tabs/tab being not compatible with TB.
So, maybe it makes sense to figure out why tabs/tab gets pulled if I require pageMod. Maybe there's an unnecessary dependency that can be broken, don't know. Or maybe we figure out where this check is made and just try to skip it for TB.

Does any of this makes sense?
Cheers

Frédéric WANG

unread,
Nov 22, 2014, 5:42:27 AM11/22/14
to Giuseppe Piscopo, mozilla-la...@googlegroups.com
Le 21/11/2014 21:21, Giuseppe Piscopo a écrit :

Giuseppe: I don't really know the addon-sdk codebase but I guess that if
page-mod has a require("tabs/tab") then it really needs that module...
My understanding is that
https://bugzilla.mozilla.org/show_bug.cgi?id=1071048 changed the tab
module to claim it compatible on all platforms and thus also made
page-mod working on SeaMonkey
(https://bugzilla.mozilla.org/show_bug.cgi?id=1023661 was not necessary
here, sorry for the confusion). However, from your testing this claim
was wrong for Thunderbird :-(

To come back to your initial problem, I see three possibilities:

1) The add-on sdk does not seem to work well with Thunderbird at the
moment and I don't think it's part of Mozilla Corporation's plan to fix
that, so try an alternative method to write a Thunderbird extension. Of
course that might not be as easy as using the add-on SDK. This user
group is probably not the best place to discuss that so I'd suggest to
contact Thunderbird folks instead.

2) Keep using the add-on sdk to generate your add-on but patch the
output code to address differences between Firefox & Thunderbird (like
what http://addonconverter.fotokraina.com/ does for SeaMonkey). However
SeaMonkey people said that AMO reviewers won't accept patched SDK
(https://bugzilla.mozilla.org/show_bug.cgi?id=1060858#user_story_header).

3) Fix the add-on SDK to make enough module compatible with Thunderbird
to write your extension. This would be the ideal option, but I'm not
sure how much we can do here :-( At least Philip Chee already commented
on the context-menu: https://bugzilla.mozilla.org/show_bug.cgi?id=1100644#c8

--
Frédéric Wang
maths-informatique-jeux.com/blog/frederic


signature.asc

Adrian Aichner

unread,
Nov 22, 2014, 6:17:14 AM11/22/14
to mozilla-la...@googlegroups.com

On 22.11.2014 11:42, Frédéric WANG wrote:

...
> 3) Fix the add-on SDK to make enough module compatible with Thunderbird
> to write your extension. This would be the ideal option, but I'm not
> sure how much we can do here :-( At least Philip Chee already commented
> on the context-menu: https://bugzilla.mozilla.org/show_bug.cgi?id=1100644#c8
>
The #jetpack and #thunderbird channels may be useful to further this cause.

A developer in #jetpack said while they don't actively support
Thunderbird they are open to accept patches.

I think the add-on SDK already working in firefox on linux, mac,
windows, android with its support for commonJS style modules is really
ahead of the Google Chrome Extension system and we should build on that.

Adrian

Giuseppe Piscopo

unread,
Nov 22, 2014, 11:58:04 AM11/22/14
to mozilla-la...@googlegroups.com
Uhm... 
Thanks both for your suggestions. Trying to put thoughts together:

I'd like to put just some more efforts in this, before backing out and forget about all this mess.
Initial aims where to build a TB add-on, useful for me and useful (possibly) for others, so to be eventually approved and published. And I wanted to do this using latest web techonologies, which by the way are the ones that I know. I'm willing to dive into unknowns like Python CFX, if they make things easier, and JPM, if they're open to future development, but I don't feel like learning another XML-like XUL. 
It seems to me that Mozilla is just leaving TB behind, at least TB Addon extension, but let's just move away from rants here.

I'd put some effort in option 3), just to try. It can be with cfx, but I might also try with JPM if that could bring somewhere.

My understanding is that changes to engines metadata in add-on sdk are useless, so I don't get how cfx or whatever else determines compatibility. And also, I follows that those bugfixes at the moment do nothing in TB.
I got that if I want to make tests with locally patched add-on sdk I cannot just cfx run but I have to zip sdk with my addon XPI and install that in TB.

If I install the XPI, I see a bunch of console messages that do not easily translate to something happening in my addon, even with a dumb one. So I don't see a way to work and patch sdk, if I cannot understand what's happening from console. Not to mention no debbugging whatsoever.

If I don't install the XPI and just cfx run, I guess TB is using its own internal sdk. In this context I can see log messages that I understand, and I could to track back why tabs are needed if I require pageMod (more on this later).

How would you suggest to move on from here?

In closing, about the issue with pageMod and tabs:
one of the reasons pageMod uses tabs is e.g. because "content window", where content script is attached I guess, can only exist in the context of tabs: 

addon-sdk\lib\sdk\page-mod.js: #173
  // We apply only on documents in tabs of Firefox
  if (!getTabForContentWindow(window))
    return;

#188
function applyOnExistingDocuments (mod) {
  getTabs().forEach(tab => {
    // Fake a newly created document
    let window = getTabContentWindow(tab);

Apart from everything mentioned above, it would be nice to understand how (if) this maps to TB, e.g. if content windows are in tabs as well or what.

Cheers

Frédéric WANG

unread,
Nov 22, 2014, 12:34:20 PM11/22/14
to mozilla-la...@googlegroups.com
Le 22/11/2014 17:58, Giuseppe Piscopo a écrit :

@Giuseppe:

I'm not sure you really understood what my attempt in bug 1100644 was so
just to clarify:

1) When Thunderbird is not indicated in the module.metadata, the module
will just fail to load with the error message that you said is
"understandable". However, this is really meaningless to know whether
the module is supported or not (for example on the dev version,
clipboard.js is wrongly claimed to be incompatible while tab.js is
wrongly claimed to be compatible).

2) My "bug fixes" are really just changing the module to say they are
compatible. Again, this might be enough in some cases (for example for
the module clipboard.js) but for most UI modules this is not enough (for
example context-menu.js etc). Thunderbird internal XUL is quite
different from Firefox, so more work will be needed, I'm afraid. As I'm
not familiar with Thunderbird codebase, I'm not sure I can really help
here. However, claiming the module to be compatible is a first step for
someone more knowledgeable to try and debug the Javascript errors that
you said are not understandable.

3) We have to distinguish the cfx program VS the sdk modules when we say
"Thunderbird is not supported". The fact that we can not simply use "cfx
run", "cfx test" that we have to modify install.rdf by hand or use
special options for "cfx xpi" are really (painful) issues in cfx rather
than bugs in the sdk modules (I'm really mainly focused on fixing the
latter here). Similarly, jpm is merely a rewriting of cfx using nodejs
instead of Python: the program that generates the XPI will be different
(and so we can get some improvements like avoiding to modify install.rdf
by hand), but the sdk modules bundled in Thunderbird will remain the
same (and so that won't help either for the compatibility issue).

> How would you suggest to move on from here?

I would suggest to ask advice to some Thunderbird people regarding

1) What would be the best way for you to write your add-on and how much
work that would be.
2) Whether they can help to fix some of the UI modules in the add-on
sdk, which is really the main issue here.

--
Frédéric Wang
maths-informatique-jeux.com/blog/frederic


signature.asc

Adrian Aichner

unread,
Nov 22, 2014, 2:16:41 PM11/22/14
to mozilla-la...@googlegroups.com

On 22.11.2014 18:34, Frédéric WANG wrote:
> Le 22/11/2014 17:58, Giuseppe Piscopo a écrit :
>
> @Giuseppe:
>
> I'm not sure you really understood what my attempt in bug 1100644 was so
> just to clarify:
>
> 1) When Thunderbird is not indicated in the module.metadata, the module
> will just fail to load with the error message that you said is
> "understandable". However, this is really meaningless to know whether
> the module is supported or not (for example on the dev version,
> clipboard.js is wrongly claimed to be incompatible while tab.js is
> wrongly claimed to be compatible).
>
> 2) My "bug fixes" are really just changing the module to say they are
> compatible. Again, this might be enough in some cases (for example for
> the module clipboard.js) but for most UI modules this is not enough (for
> example context-menu.js etc). Thunderbird internal XUL is quite
> different from Firefox, so more work will be needed, I'm afraid. As I'm
> not familiar with Thunderbird codebase, I'm not sure I can really help
> here. However, claiming the module to be compatible is a first step for
> someone more knowledgeable to try and debug the Javascript errors that
> you said are not understandable.

Just in case you have not done that yet:

It is possible to debug thunderbird remotely from firefox:

https://developer.mozilla.org/en-US/docs/Tools/Remote_Debugging/Thunderbird

Be aware of the trap I tripped up in: The cygwin Xwin server I
occasionally start on my Windows XP laptop is also running on port 6000,
causing this connection attempt to time out.

Once I stop that I am able to connect, using above instructions.

I connect to the Main Process from firefox and the Debug tab reveals
that thunderbird only has the loader and promise module:

Add-on SDK
toolkit/loader.js
sdk/core/promise.js

Both have
module.metadata = {
'stability': 'unstable'
};

I have not yet tried to debug an Add-on with bundled SDK.

Adrian

Adrian Aichner

unread,
Nov 22, 2014, 6:14:18 PM11/22/14
to mozilla-la...@googlegroups.com
I was able to do some debugging of my add-on
https://addons.mozilla.org/en-US/firefox/addon/jot/ in thunderbird
31.2.0 now.

For that I edited jot.xpi with Emacs and used
Install Add-on from File
in the
Thunderbird Add-on Manager
again and again.

main.js has a debugger statement, so that I can turn all console
statements on manually
Set DEBUG_ADDON = true in the debugger.

I had to add Thunderbird to:
install.rdf
sdk/tabs.js
sdk/tabs/tab.js
sdk/context-menu.js
sdk/selection.js

The context menu stuff does not work at all, but add-on de/activation
prints useful information.

Also the inline options in AOM work, except for the [ Report Bugs,
Suggest Features ] control (button).

I also have some logic to un/hide most options which works too in AOM
for Jot!

This is a fairly powerful debug environment, although I am currently
stuck trying to get tabs or windows to open, or the context-menu to get
hooked in.

I would still call it progress...

Adrian

Giuseppe Piscopo

unread,
Nov 23, 2014, 6:41:30 AM11/23/14
to mozilla-la...@googlegroups.com
Frédéric: probably you're right, I don't get that completely. I saw that some bugfixes where adding SeaMonkey to the metadata. But then in master dev version I see that engines metadata are removed altogether. So, trying to patch the dev version of sdk, what should I do for TB? Leave no engines metadata, or add engines and add TB to that?

Adrian: thanks, yes, I tried remote debugging through FF in the past. I was debugging the Compose window Send events, and at some point I think I was able to debug that. But when I tried debugging something more "fundamental" in my addon (I think it was main.js) I was not able. But then again I did not try attaching to main process, I think I always tried with some window. So I could try that again.

BTW, it's symptomatic that in linked remote debugging page it says "[...] As Thunderbird's notion of tabs doesn't match Firefox, the remote tabs area shows all xul:browser elements in Thunderbird. [...]" :)
Reply all
Reply to author
Forward
0 new messages