Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property '_ownerDocument' of undefined #266

Closed
level09 opened this issue Aug 2, 2011 · 19 comments
Closed

TypeError: Cannot read property '_ownerDocument' of undefined #266

level09 opened this issue Aug 2, 2011 · 19 comments

Comments

@level09
Copy link

level09 commented Aug 2, 2011

/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/level1/core.js:458
if (!newChild._ownerDocument) newChild._ownerDocument = this._ownerDocumen
^
TypeError: Cannot read property '_ownerDocument' of undefined
at Object. (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/level1/core.js:458:18)
at Object.insertBefore (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/level2/events.js:325:20)
at Object.appendChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/level1/core.js:574:17)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:167:17)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)

@tmpvar
Copy link
Member

tmpvar commented Aug 2, 2011

please provide some context. which method are you using? what does the markup look like? etc..

On Aug 2, 2011, at 1:01 PM, level09 wrote:

/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/level1/core.js:458
if (!newChild._ownerDocument) newChild._ownerDocument = this._ownerDocumen
^
TypeError: Cannot read property '_ownerDocument' of undefined
at Object. (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/level1/core.js:458:18)
at Object.insertBefore (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/level2/events.js:325:20)
at Object.appendChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/level1/core.js:574:17)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:167:17)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)
at setChild (/usr/local/lib/node/.npm/jsdom/0.2.1/package/lib/jsdom/browser/htmltodom.js:163:7)

Reply to this email directly or view it on GitHub:
#266

@level09
Copy link
Author

level09 commented Aug 2, 2011

Here is the HTML :

https://gist.github.com/1121208

that used to work fine with older versions of jsdom. let me know if I can provide more details.

@level09
Copy link
Author

level09 commented Aug 2, 2011

the method is jsdom.env(html, [scripts],function(err,window) { })

@tmpvar
Copy link
Member

tmpvar commented Aug 2, 2011

what scripts are you injecting?

On Aug 2, 2011, at 3:29 PM, level09 wrote:

the method is jsdom.env(html, [scripts],function(err,window) { })

Reply to this email directly or view it on GitHub:
#266 (comment)

@level09
Copy link
Author

level09 commented Aug 2, 2011

I am only injecting latest jquery : http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js

@tmpvar
Copy link
Member

tmpvar commented Aug 2, 2011

weird. thanks for reporting

On Aug 2, 2011, at 3:36 PM, level09 wrote:

I am only injecting latest jquery : http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js

Reply to this email directly or view it on GitHub:
#266 (comment)

@mabeyj
Copy link
Contributor

mabeyj commented Aug 3, 2011

I came across this error and was able to reduce it to this test case:

var jsdom = require('jsdom').jsdom;
var doc = jsdom('<html><body><input value="<"></body></html>');

The original document had "<" in an attribute value and was considered valid according to the W3C validator, but triggered this error.

@tmpvar
Copy link
Member

tmpvar commented Aug 3, 2011

makes sense, this looks like its a node-htmlparser issue

@RobertCZ
Copy link

RobertCZ commented Aug 6, 2011

Just wanted to report probably the same error, my reduced test case was '<< prev'

@RobertCZ
Copy link

RobertCZ commented Aug 6, 2011

ups...

<html><body><< prev</body></html>

@showersky
Copy link

I also had this problem. When I use jsdom.env to open www.amazon.com, this error will occur. It is related to html parse. But I do not know how to fix it. Any solution?

@tmpvar
Copy link
Member

tmpvar commented Aug 8, 2011

there are two routes we can take.

  1. report this as an error to node-htmlparser
  2. patch the layer between the parser and jsdom to catch these errors and report them (without terminating the parse or the process)

@level09
Copy link
Author

level09 commented Aug 9, 2011

already reported to node-htmlparser

@jhurliman
Copy link
Contributor

What work is involved in the second route? Is it something I could help with?

@tmpvar
Copy link
Member

tmpvar commented Aug 22, 2011

Just so it's clear, I'm not sold on the name "trigger" but the work to rename it should be done separately

@jhurliman
Copy link
Contributor

#279 should fix this issue without needing to enter a try/catch block

@domenic
Copy link
Member

domenic commented Oct 10, 2012

The crash is no longer present, so this reduces to a duplicate of #494.

@domenic domenic closed this as completed Oct 10, 2012
@GianlucaGuarini
Copy link
Contributor

I still have this issue by using a custom html tag:

jsdom.env('<!doctype html><html><head></head><body><' + myComponent +'/></body></html>', function (errors, window) {
  global.document = window.document
  console.log(document.body.innerHTML) // <my-component></my-component>
})

@domenic
Copy link
Member

domenic commented Feb 27, 2015

@GianlucaGuarini please open a new bug instead of commenting on an old bug; include the full error thrown with the stack trace, and make sure you are using the latest version of jsdom, 4.0.1 on io.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants