document.body is null

613 views
Skip to first unread message

Bjorn Tipling

unread,
Mar 7, 2011, 9:43:11 PM3/7/11
to jsdom
Attempting to appendChild on body results in an error:


document.body.appendChild(el);
^
TypeError: Cannot call method 'appendChild' of null
at [object Object].initialize ([object Context]:4013:21)
at Object._onTimeout ([object Context]:4436:16)
at Timer.callback (timers.js:62:39)

Any ideas?

Bjorn Tipling

unread,
Mar 7, 2011, 9:49:33 PM3/7/11
to jsdom
I should note that this line is an external script requested as part
of the call to jsdom.jsdom it's not in the node.js code that has
access to the result of jsdom.jsdom

Bjorn Tipling

unread,
Mar 7, 2011, 9:59:22 PM3/7/11
to jsdom
If I try to use jsdom.env and in the callback attempt to access
window.documen.body it is null. :/

Bjorn Tipling

unread,
Mar 7, 2011, 10:00:09 PM3/7/11
to jsdom
I meant window.document.body is null.

Bjorn Tipling

unread,
Mar 7, 2011, 10:06:24 PM3/7/11
to jsdom
I have been stepping through some of the jsdom/level2 files and it
looks like the document doesn't have any child elements.

Bjorn Tipling

unread,
Mar 8, 2011, 1:01:18 PM3/8/11
to jsdom
Aha, use of document.write was killing it!

jscheel

unread,
Mar 8, 2011, 2:22:05 PM3/8/11
to jsdom
So, is there a way around this? While we all hate document.write, it's
still a common thing on the web, especially for things like google
analytics trackers, etc.

hob...@gmail.com

unread,
Mar 8, 2011, 5:11:55 PM3/8/11
to js...@googlegroups.com
On Mar 8, 2011, at 10:01 AM, Bjorn Tipling wrote:

> Aha, use of document.write was killing it!

document.write() blows away the document if it's called when the HTML parser's insertion point is undefined:

http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in-html-documents.html#document.write()


Ted

Bjorn Tipling

unread,
Mar 8, 2011, 8:54:55 PM3/8/11
to jsdom
Well there isn't any problem when running it in any browser, so it
seems like jsdom is definitely doing something differently.

On Mar 8, 2:11 pm, hob...@gmail.com wrote:
> On Mar 8, 2011, at 10:01 AM, Bjorn Tipling wrote:
>
> > Aha, use of document.write was killing it!
>
> document.write() blows away the document if it's called when the HTML parser's insertion point is undefined:
>
> http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in-h...()
>
> Ted
Reply all
Reply to author
Forward
0 new messages