Jetpack SDK and XUL extensions

55 views
Skip to first unread message

Nickolay Ponomarev

unread,
Mar 28, 2010, 4:44:47 PM3/28/10
to mozilla-labs-jetpack
Hi,

While it's not advertised in the announcement, it's possible to use
Jetpack SDK with regular (XUL) extensions, which is useful if you want
to use the "modules" functionality or planning to switch to Jetpack
incrementally.

http://asqueella.blogspot.com/2010/03/jetpack-sdk-and-xul-extensions.html

Thought it might be interesting to old-time developers watching the
Jetpack effort.

Nickolay

grbradt

unread,
Mar 29, 2010, 12:35:10 AM3/29/10
to mozilla-labs-jetpack
Hi,
I tried this with one of my own extensions, and worked nicely, thanks!
However, when I tried to install and use the .xpi from step 8, I got
the following error in the console:

Error: directory not found: C:\Documents and Settings\grbradt
\Application Data\Mozilla\Firefox\Profiles\tmc20g12.jetpack\extensions
\simpl...@grbradt.org\resources\ace682b1-aefe-4d86-
a392-4067cbf46340-simpletimer-tests
Source file:
file:///C:/Documents%20and%20Settings/grbradt/Application%20Data/Mozilla/Firefox/Profiles/tmc20g12.jetpack/extensions/simpl...@grbradt.org/components/harness.js
Line: 107

My resources folder contains only ...jetpack-core-lib
and ...simpletimer-lib directories.
(My tests folder created in step 6 is empty)
Any idea what the problem is?
Running Win XP and Fx 3.6.2

Thanks,
George


On Mar 28, 4:44 pm, Nickolay Ponomarev <asquee...@gmail.com> wrote:
> Hi,
>
> While it's not advertised in the announcement, it's possible to use
> Jetpack SDK with regular (XUL) extensions, which is useful if you want
> to use the "modules" functionality or planning to switch to Jetpack
> incrementally.
>

> http://asqueella.blogspot.com/2010/03/jetpack-sdk-and-xul-extensions....

Atul Varma

unread,
Mar 29, 2010, 12:52:56 AM3/29/10
to mozilla-la...@googlegroups.com, grbradt
Oh, the test directory isn't actually included in built XPIs--it's only
available when you use 'cfx test', which effectively adds the test
directory and some other stuff. We could add a command-line switch for
including the tests, though... Does using 'cfx test' work for your use case?

By the way, Nickolay, this is an excellent guide! Would you be
interested in possibly contributing it as one of the appendices in the SDK?

- Atul

grbradt

unread,
Mar 29, 2010, 1:43:55 AM3/29/10
to mozilla-labs-jetpack
Hi,
Running cfx test prior to building .xpi did not result in the addition
of the directory. If I manually add the test directory to the .xpi,
then it works fine.

Regards,
George

On Mar 29, 12:52 am, Atul Varma <ava...@mozilla.com> wrote:
> Oh, the test directory isn't actually included in built XPIs--it's only
> available when you use 'cfx test', which effectively adds the test
> directory and some other stuff.  We could add a command-line switch for
> including the tests, though... Does using 'cfx test' work for your use case?
>
> By the way, Nickolay, this is an excellent guide!  Would you be
> interested in possibly contributing it as one of the appendices in the SDK?
>
> - Atul
>
> On 3/28/10 9:35 PM, grbradt wrote:
>
> > Hi,
> > I tried this with one of my own extensions, and worked nicely, thanks!
> > However, when I tried to install and use the .xpi from step 8, I got
> > the following error in the console:
>
> > Error: directory not found: C:\Documents and Settings\grbradt
> > \Application Data\Mozilla\Firefox\Profiles\tmc20g12.jetpack\extensions

> > \simpleti...@grbradt.org\resources\ace682b1-aefe-4d86-
> > a392-4067cbf46340-simpletimer-tests
> > Source file:
> > file:///C:/Documents%20and%20Settings/grbradt/Application%20Data/Mozilla/Firefox/Profiles/tmc20g12.jetpack/extensions/simpleti...@grbradt.org/components/harness.js

Nickolay Ponomarev

unread,
Mar 29, 2010, 6:17:39 AM3/29/10
to mozilla-la...@googlegroups.com
On Mon, Mar 29, 2010 at 8:52 AM, Atul Varma <ava...@mozilla.com> wrote:
By the way, Nickolay, this is an excellent guide!  Would you be interested in possibly contributing it as one of the appendices in the SDK?

Thanks. Yes, feel free to use it; I'll submit a patch sometime later.

Nickolay

Rezwana Karim Nawrin

unread,
May 26, 2010, 5:31:45 PM5/26/10
to mozilla-labs-jetpack
Hi,
thanks for including this example in jetpack sdk-0.3 and
onwards. As illustrated in the documentation,
https://jetpack.mozillalabs.com/sdk/0.3/docs/#guide/xul-extensions,
this works fine. According to the documentation, if I paste the code
in the error console to invoke modules from extension code as follows,
this works fine.

we can use CommonJS modules from regular extension code using this
code:

function loadJetpackModule(module) {
return Components.classes[
"@mozilla.org/harness-service;1?id=te...@example.com"].
getService().wrappedJSObject.loader.require(module);
}
alert(loadJetpackModule("my-module").add(1, 3)); // alerts 4!

however, if i try to use the same code inside the extension, it get
stuck and does not do anything, let alone printing the alert with '4'.
I have tried with two small extension, web2pdf and commentblocker but
faced the same problem. No error message is printed either in the
terminal or console, so could not figure out the root cause of the
problem. Any help will be appreciated.

Nickolay Ponomarev

unread,
May 26, 2010, 6:02:06 PM5/26/10
to mozilla-la...@googlegroups.com
On Thu, May 27, 2010 at 1:31 AM, Rezwana Karim Nawrin <rezwana.k...@gmail.com> wrote:
we can use CommonJS modules from regular extension code using this
code:
[...]

however, if i try to use the same code inside the extension, it get
stuck

I don't understand the difference between the working scenario and the failing one. Can you clarify? Or perhaps post the source you're testing with somewhere and the steps to reproduce the problem?

Nickolay

Rezwana Karim Nawrin

unread,
May 26, 2010, 6:20:51 PM5/26/10
to mozilla-la...@googlegroups.com
Working scenario:
       If i paste the code in the error console as suggested by the sdk documentation, it works fine and shows an alert box with summation result 4.

Failing scenario:
       The normal web2pdf JSE works in this way, you have to open a page and click the icon, then the 3rd party web page is opened in a separate tab which converts the web page to a pdf.
       I am trying to convert it to Jetpack. I used the same code for invoking a jetpack module inside web2pdf extension code in web2pdf.js file  and modified the code such that now the loadJetpackModule is a  function declared inside the .js file. Now whenever a button is clicked the following line will be executed and then the document will be converted to pdf by the 3rd party web page opened in a separte page..
alert(loadJetpackModule("my-module").add(1, 3)); 

however after this modification, nothing happens and it gets stuck over there.




Nickolay

--
You received this message because you are subscribed to the Google Groups "mozilla-labs-jetpack" group.
To post to this group, send email to mozilla-la...@googlegroups.com.
To unsubscribe from this group, send email to mozilla-labs-jet...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mozilla-labs-jetpack?hl=en.

Nickolay Ponomarev

unread,
May 26, 2010, 6:31:18 PM5/26/10
to mozilla-la...@googlegroups.com
On Thu, May 27, 2010 at 2:20 AM, Rezwana Karim Nawrin <rezwana.k...@gmail.com> wrote:
Working scenario:
       If i paste the code in the error console as suggested by the sdk documentation, it works fine and shows an alert box with summation result 4.

OK, this means the component is registered and is functioning normally.
 
Failing scenario:
       The normal web2pdf JSE works in this way, you have to open a page and click the icon, then the 3rd party web page is opened in a separate tab which converts the web page to a pdf.
       I am trying to convert it to Jetpack. I used the same code for invoking a jetpack module inside web2pdf extension code in web2pdf.js file  and modified the code such that now the loadJetpackModule is a  function declared inside the .js file. Now whenever a button is clicked the following line will be executed and then the document will be converted to pdf by the 3rd party web page opened in a separte page..
alert(loadJetpackModule("my-module").add(1, 3));

however after this modification, nothing happens and it gets stuck over there.
By "console" you mean Tools>Error Console, right? And you have the dev prefs <https://developer.mozilla.org/en/Setting_up_extension_development_environment#Development_preferences> set, javascript.options.showInConsole = true in particular?

Does alert(1) work? (if it doesn't, what context the JS code is loaded in? an overlay, an XPCOM component, a CommonJS module? The latter two don't have alert().

Does alert(Components.classes) work?

Are you testing this code just after you successfully run the snippet in the Error Console -- without making any changes or restarting Firefox?

Nickolay

Rezwana Karim Nawrin

unread,
May 26, 2010, 6:56:17 PM5/26/10
to mozilla-la...@googlegroups.com
On Wed, May 26, 2010 at 6:31 PM, Nickolay Ponomarev <asqu...@gmail.com> wrote:
On Thu, May 27, 2010 at 2:20 AM, Rezwana Karim Nawrin <rezwana.k...@gmail.com> wrote:
Working scenario:
       If i paste the code in the error console as suggested by the sdk documentation, it works fine and shows an alert box with summation result 4.

OK, this means the component is registered and is functioning normally.
 
Failing scenario:
       The normal web2pdf JSE works in this way, you have to open a page and click the icon, then the 3rd party web page is opened in a separate tab which converts the web page to a pdf.
       I am trying to convert it to Jetpack. I used the same code for invoking a jetpack module inside web2pdf extension code in web2pdf.js file  and modified the code such that now the loadJetpackModule is a  function declared inside the .js file. Now whenever a button is clicked the following line will be executed and then the document will be converted to pdf by the 3rd party web page opened in a separte page..
alert(loadJetpackModule("my-module").add(1, 3));

however after this modification, nothing happens and it gets stuck over there.
By "console" you mean Tools>Error Console, right? And you have the dev prefs <https://developer.mozilla.org/en/Setting_up_extension_development_environment#Development_preferences> set, javascript.options.showInConsole = true in particular?

 Yes earlier when i wrote console ,I meant Tools->Error console. so far , javascript.options.showInConsole was set to false. I changed it true . And now the it says that loadJetpackModule function is not defined.
 

Does alert(1) work? (if it doesn't, what context the JS code is loaded in? an overlay, an XPCOM component, a CommonJS module? The latter two don't have alert().

    I have tried with alert("hello world") . It works fine. Problem occurs when the loadJetpackModule is invoked within alert().

Does alert(Components.classes) work?

Are you testing this code just after you successfully run the snippet in the Error Console -- without making any changes or restarting Firefox?

I have tried both i.e. just after successfully  run in the error console without restarting firefox and with restarting firefox. same result.



from this error, i think somehow it is not recognizing the loadJetpackModule function. The way i defined it  in web2pdf.js file is as below.

const web2pdf = {
  .............
  ...........
  loadJetpackModule: function (module) {

      return Components.classes[
     "@mozilla.org/harness-service;1?id=te...@example.com"].
     getService().wrappedJSObject.loader.require(module);
  },

  onClick : function (){   
     alert(loadJetpackModule("my-module").add(1, 3));
     .....................................
   },
...............................................
 ....................................
 window.addEventListener( 'load', web2pdf, false);
}

and this .js file is inside the packages/my-package/extension/chrome/content directory.

thanks


Nickolay Ponomarev

unread,
May 27, 2010, 4:09:36 AM5/27/10
to mozilla-la...@googlegroups.com
On Thu, May 27, 2010 at 2:56 AM, Rezwana Karim Nawrin <rezwana.k...@gmail.com> wrote:
 Yes earlier when i wrote console ,I meant Tools->Error console. so far , javascript.options.showInConsole was set to false. I changed it true . And now the it says that loadJetpackModule function is not defined.
 
Great!
 
Does alert(1) work? (if it doesn't, what context the JS code is loaded in? an overlay, an XPCOM component, a CommonJS module? The latter two don't have alert().

I have tried with alert("hello world") . It works fine. Problem occurs when the loadJetpackModule is invoked within alert().
from this error, i think somehow it is not recognizing the loadJetpackModule function. The way i defined it  in web2pdf.js file is as below.

const web2pdf = {
  .............
  ...........
  loadJetpackModule: function (module) {

      return Components.classes[
     "@mozilla.org/harness-service;1?id=te...@example.com"].
     getService().wrappedJSObject.loader.require(module);
  },

  onClick : function (){   

     alert(loadJetpackModule("my-module").add(1, 3));
     .....................................
   },

Oh, you need to use  web2pdf.loadJetpackModule or this.loadJetpackModule

You should read something on JS, maybe this: http://mdn.beonex.com/en/A_re-introduction_to_JavaScript#Custom_objects

Nickolay

Rezwana Karim Nawrin

unread,
May 27, 2010, 9:26:33 AM5/27/10
to mozilla-la...@googlegroups.com

 this.loadJEtpackModule() works fine. I should have figured that out earlier :(.

Thanks for helping me. And also thanks for the link. :)


Rezwana

Luca Greco

unread,
Jun 1, 2010, 9:42:46 AM6/1/10
to mozilla-la...@googlegroups.com
There seems to be a moderate interest in interoperability between the
new jetpack-sdk world and the old XUL world,
I'm updating my proposed patches from time to time, but IMHO only
after proposed and discussed a JEP, we will be
able to connect this two worlds correctly.

So I'm proposing a draft of such JEP (based on my current patches and
some other thoughts):

https://wiki.mozilla.org/User:RPL/drafts/JEP_xyz_Chrome_Support

Is there anyone (besides me) interested to this sorts of JEP?
Is there any interest to merge this sorts of things?
Some other thoughts?

Happy hacking to all,
rpl

--
Luca Greco @ Alca Società Cooperativa
Follow me on http://twitter.com/lucagreco

amolsarmalkar

unread,
Jul 1, 2010, 3:57:26 AM7/1/10
to mozilla-labs-jetpack
I followed the steps given in article
http://asqueella.blogspot.com/2010/03/jetpack-sdk-and-xul-extensions.html

I have one toolbar xul extension.I am using jetpack sdk 0.5.But after
running the command
cfx run -a firefox -t extension ,I get certain errors.

What should be the value of -t parameter in above command.If I give -
t the path as "C:\jetpack-sdk-0.5\packages\my-extension" then FF gets
launched without my xul extension installed.


On May 27, 6:26 pm, Rezwana Karim Nawrin
<rezwana.karimnaw...@gmail.com> wrote:
>  this.loadJEtpackModule() works fine. I should have figured that out earlier
> :(.
>
> Thanks for helping me. And also thanks for the link. :)
>
> Rezwana
>
> On Thu, May 27, 2010 at 4:09 AM, Nickolay Ponomarev <asquee...@gmail.com>wrote:
>
>
>
> > On Thu, May 27, 2010 at 2:56 AM, Rezwana Karim Nawrin <
> > rezwana.karimnaw...@gmail.com> wrote:
>
> >>  Yes earlier when i wrote console ,I meant Tools->Error console. so far ,
> >> *javascript.options.showInConsole* was set to false. I changed it true .
> >> And now the it says that loadJetpackModule function is not defined.
>
> > Great!
>
> >>  Does alert(1) work? (if it doesn't, what context the JS code is loaded
> >>> in? an overlay, an XPCOM component, a CommonJS module? The latter two don't
> >>> have alert().
>
> >> I have tried with alert("hello world") . It works fine. Problem occurs
> >> when the loadJetpackModule is invoked within alert().
>
> >> from this error, i think somehow it is not recognizing the
> >> loadJetpackModule function. The way i defined it  in web2pdf.js file is as
> >> below.
>
> >> const web2pdf = {
> >>   .............
> >>   ...........
> >>   loadJetpackModule: function (module) {
>
> >>       return Components.classes[
> >>      "@mozilla.org/harness-service;1?id=t...@example.com"].
> >>      getService().wrappedJSObject.loader.require(module);
> >>   },
>
> >>   onClick : function (){
>
> >>      alert(loadJetpackModule("my-module").add(1, 3));
> >>      .....................................
> >>    },
>
> >>  Oh, you need to use  web2pdf.loadJetpackModule or this.loadJetpackModule
>
> > You should read something on JS, maybe this:
> >http://mdn.beonex.com/en/A_re-introduction_to_JavaScript#Custom_objects
>
> > Nickolay
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "mozilla-labs-jetpack" group.
> > To post to this group, send email to mozilla-la...@googlegroups.com
> > .
> > To unsubscribe from this group, send email to
> > mozilla-labs-jet...@googlegroups.com<mozilla-labs-jetpack%2Bun­subs...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/mozilla-labs-jetpack?hl=en.- Hide quoted text -
>
> - Show quoted text -

Sam

unread,
Aug 3, 2010, 8:27:03 AM8/3/10
to mozilla-labs-jetpack
Hi,

I am also having issues in porting my xul based toolbar to jetpack.

I have followed the steps as mentioned in the same link as given in
above mail.

But I donot see my toolbar.

Pls. help.

Sam

On Jul 1, 12:57 pm, amolsarmalkar <amolsarmal...@gmail.com> wrote:
> I followed the steps given in articlehttp://asqueella.blogspot.com/2010/03/jetpack-sdk-and-xul-extensions....
> > >http://groups.google.com/group/mozilla-labs-jetpack?hl=en.-Hide quoted text -

Marcio Galli

unread,
Aug 3, 2010, 9:42:42 AM8/3/10
to mozilla-la...@googlegroups.com
BTW while at the Mozilla Summit 2010 in Canada, the Jetpack team did a
local small contest and I decided to test this hybrid approaach with
my submission. It worked nice using the existing docs provided by the
localhost in the SDK. However, as reported in that submission, I
found a typo -- see the three quotes:

* From the Jetpack SDK docs, localhost and online, pages:

function loadJetpackModule(module) {
return Components.classes[
"@mozilla.org/harness-service;1?id="jid0-i6WjYzrJ0UFR0pPPM7Znl3BvYbk"].
getService().wrappedJSObject.loader.require(module);
}

m

> To unsubscribe from this group, send email to mozilla-labs-jet...@googlegroups.com.


> For more options, visit this group at http://groups.google.com/group/mozilla-labs-jetpack?hl=en.
>
>

--
blog.taboca.com

Sam

unread,
Aug 5, 2010, 1:27:35 AM8/5/10
to mozilla-labs-jetpack
Hi,

I was able to integrate xul and jetpack and was able to install it on
my firefox 3.6. But on installation, it is asking me to restart the
browser for the installation to complete. On the other hand, I tried
to install it on FF4.0beta 1 and i am getting an error "The download
of file failed : -3".

Why the addon is not able to install it on FF 4.0 beta 1 ? Also why
jetpack addon is restarting the browser ?

I need to address the above questions ?

Pls. help.

Sam
> >> > >http://groups.google.com/group/mozilla-labs-jetpack?hl=en.-Hidequoted text -
Reply all
Reply to author
Forward
0 new messages