-
Notifications
You must be signed in to change notification settings - Fork 43
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
Usage w/ Jsdom: TypeError: Cannot read property 'href' of undefined #26
Comments
Can you provide the smallest subset of the HTML code that causes this error? Also, information on the environment in which this occurred (browser, os, incognito or not, etc) would be very helpful. |
I'm afraid I can't, as the page I am scraping via But it has a bunch of Javascript in it, which I have to evaluate using JSDom's It's also got a few hidden iframes and jQuery usage, some shadow dom stuff, as far as I can see. Not sure if any of this could be an issue? |
Hmmm, it will be really hard to help without more information. Can you at least tell me what type of node (tagName, attribute, etc) is the last to be visited before the error is thrown? |
Ok, that's a much more solvable issue. What btowser/os/environment is this occurring in? |
Windows 10, 64bit. |
Ah, you're using jsDOM, I missed that. I'm not very familiar with that library, but here is my suspicion: almost all browsers (at least all of the IE8+ ones) set |
Ok, attempted a fix with this commit. Can you please try it and let me know if it works? |
Just to be clear, you are getting that error even when using jsdom-global? |
Also worth reading: jsdom/jsdom#1388 and https://github.com/tmpvar/jsdom#simple-options. My feeling is that this is an issue with jsDOM not implementing a (very) standard portion of the DOM spec more than it is a bug with this library per se. Also, its worth noting that jsDOM is not one of the (psuedo-)browsers listed as being supported in the README... That being said, I do recognize that this library should be usable in browsers that almost but not quite simulate the real thing, so if there's an easy fix, I'm happy to put it in. I just want to make sure we exhaust all of the options that involve configuring or extending jsDOM itself first. |
I guess that's quite possible. I'll give the options a few more tries. Based on other issues and stackoverflow, I had tried these, which were suppose to be the common way of getting around similar problems and worked for others: JSDOM.reconfigureWindow(window, { url: 'http://localhost' })
JSDOM.reconfigureWindow(window, { location: 'http://localhost' })
JSDOM.reconfigureWindow(global.window, { url: 'http://localhost' })
window.location.href = 'http://localhost'
location.href = 'http://localhost' ...but strangely, setting href via the Since the issue does seem to originate with jsdom's output, I'll close this off. Thanks for looking into it, though! 👍 |
e.g.:
Error:
The text was updated successfully, but these errors were encountered: