document.getElementById is not a function

256 views
Skip to first unread message

Matěj Cepl

unread,
Nov 2, 2009, 4:45:26 PM11/2/09
to mozilla-la...@googlegroups.com
Hi,

I am trying to rewrite my rather largish Greasemonkey script
(http://mcepl.fedorapeople.org/scripts/bugzillaBugTriage.user.js) into
Jetpack (currently
http://mcepl.fedorapeople.org/scripts/bugzillaBugTriage.jetpack.js) and
I have to admit I am not succesful. I am working on differences (mainly
different scope for variables) by rewriting into jQuery one-liners (my
original script is very pure DOM), but now I hit this very strange
statement:

Error: document.getElementById is not a function
Source file:
file:///home/matej/.mozilla/firefox/o0b919i8.jetpack/extensions/jet...@labs.mozilla.com/content/js/ext/jquery.js
Line: 61

What?

I am currently using jetpack 0.6pre2, because 0.5 doesn't seem to be
available in Linux/x86_64 version, which leads me to another question:
will be Linux/x86_64 officially supported in 0.6 when it is released?

Third question is whether it is possible to use full strength of Firebug
for debugging jetpacks (that was one thing I missed with Greasemonkey)?
Could I put breakpoints into Jetpack code, stepping through it, etc.?

Also, somehow most of the error messages still goes to plain Firefox
Javascript console instead of the Firebug's one. Is it PEBKAC? Should I
configure something somewhere?

Thanks a lot for any replies,

Matěj Cepl
--
http://www.ceplovi.cz/matej/, Jabber: mcepl<at>ceplovi.cz
GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC

Pain is inevitable, but misery is optional. We cannot avoid pain,
but we can avoid joy.
-- Tim Hansel

Luca Greco

unread,
Nov 2, 2009, 5:04:52 PM11/2/09
to mozilla-la...@googlegroups.com
2009/11/2 Matěj Cepl <mc...@redhat.com>:

> Error: document.getElementById is not a function
> Source file:
> file:///home/matej/.mozilla/firefox/o0b919i8.jetpack/extensions/jet...@labs.mozilla.com/content/js/ext/jquery.js
> Line: 61

Can be related to jquey sandboxing (introduced from jetpack 0.5
as security feature).

Have you tried to pass the document objecte as second parameter of the
jQuery function?

Something like:

$("#myid", doc)


Happy hacking,
Luca Greco @ Alca Società Cooperativa

Matěj Cepl

unread,
Nov 3, 2009, 8:36:06 AM11/3/09
to mozilla-la...@googlegroups.com
Dne 2.11.2009 23:04, Luca Greco napsal(a):

> Can be related to jquey sandboxing (introduced from jetpack 0.5
> as security feature).
>
> Have you tried to pass the document objecte as second parameter of the
> jQuery function?
>
> Something like:
>
> $("#myid", doc)

Hmm, now it is even more weird ...

Error: document is not defined
Source file:
file:///home/matej/Dokumenty/projekty/triage/jetpack/bugzillaBugTriage.js
Line: 1369

when having this code

if (debug) {
$("#bz_field_status",document).append("<span
inline='font-size:x-small'>"+jsonDataURL+"</span>");
}

BTW, the file itself is available as
http://git.fedoraproject.org/git/triage.git?p=triage.git;a=blob_plain;f=jetpack/bugzillaBugTriage.js;hb=jetpack
(or http://is.gd/4LZEn if the previous URL gets badly broken).

Any ideas?

Matěj

Luca Greco

unread,
Nov 3, 2009, 9:42:58 AM11/3/09
to mozilla-la...@googlegroups.com
On Tue, Nov 3, 2009 at 2:36 PM, Matěj Cepl <mc...@redhat.com> wrote:
> Dne 2.11.2009 23:04, Luca Greco napsal(a):
>> Can be related to jquey sandboxing (introduced from jetpack 0.5
>> as security feature).
>>
>> Have you tried to pass the document objecte as second parameter of the
>> jQuery function?
>>
>> Something like:
>>
>> $("#myid", doc)
>
> Hmm, now it is even more weird ...
>
> Error: document is not defined
> Source file:
> file:///home/matej/Dokumenty/projekty/triage/jetpack/bugzillaBugTriage.js
> Line: 1369
>

because document is not defined in your main function's scope (remember
all your jetpack is sandboxed so there's not any document or window object
in global scope, as you surely have in a webcontent javascript script)

Try something like this:

function main(document) {
...
}

...

var callback = function(document) {
jetpack.statusBar.append({
onReady: function(widget) {
console.log("Boom!");
main(document);
},
});
};

---

Serge Bertrand

unread,
Nov 3, 2009, 8:58:10 PM11/3/09
to mozilla-la...@googlegroups.com
Now we are having the risk of falling on our head !!!
If sandboxing is generating a complex programming like that and Jquery has to be used with brand new pattern, it will make Jetpack out of reach of the "normal" (whatever it means) programmer.
By the way the wikipedia exemple (consult wikipedia in the slide bar) is also not working since 0.5, I suspect now it is the same kind of issue.
Before issuing a new release, it would be a good idea at least to run the few exemples of the official site.
We could split these tests among a few users of this forum.
--
Serge Bertrand

Matěj Cepl

unread,
Nov 4, 2009, 3:04:27 AM11/4/09
to mozilla-la...@googlegroups.com
Dne 4.11.2009 02:58, Serge Bertrand napsal(a):

> Now we are having the risk of falling on our head !!!
> If sandboxing is generating a complex programming like that and Jquery
> has to be used with brand new pattern, it will make Jetpack out of reach
> of the "normal" (whatever it means) programmer.
> By the way the wikipedia exemple (consult wikipedia in the slide bar) is
> also not working since 0.5, I suspect now it is the same kind of issue.
> Before issuing a new release, it would be a good idea at least to run
> the few exemples of the official site.
> We could split these tests among a few users of this forum.

+1000

I am now immersing myself into wonderful deep waters of OOP with
Javascript (because of global variables I don't have access to
otherwise; see bzPage on
http://git.fedorahosted.org/git/?p=triage.git;a=blob_plain;f=jetpack/bugzillaBugTriage.js;hb=jetpack),
but I really don't think this is for anyone “who can build a Web site”
(as advertised on Jetpack web page). Actually, I would say that it is
much more complicated than Greasemonkey script ever was (which is where
my script is coming from, so I know what I am talking about).

It is certainly still much less complicated than writing a proper
Firefox extension, which is what I was planning to do, so I will stick
with Jetpack for some time more, but I am quite sure I have hit couple
of thresholds of pain for most Greasemonkey script writers.

I guess we need our own wrapper around jQuery object which would hide
all this “document is not document” stuff?

Moreover, nobody answered my question about Firebug. I have now two
types of error messages (when I hit refresh button in about:jetpack, and
when I reload the page where pageMods activates) which are going
seemingly randomly to Firebug console and to the original Firefox
Javascript console. And console.log goes always to Firefox Javascript
console. Seems kind of messy.

Matěj

--
http://www.ceplovi.cz/matej/, Jabber: mcepl<at>ceplovi.cz
GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC

Nemo plus iuris ad alium transfere potest quam ipse habet.

Reply all
Reply to author
Forward
0 new messages