jsdom / jsdom

A JavaScript implementation of various web standards, for use with Node.js
MIT License
20.54k stars 1.7k forks source link

Document shows only "Location" attribute #3473

Closed TramontaG closed 1 year ago

TramontaG commented 1 year ago

Basic info:

I'm trying to use JSDOM for a webscraper and for some reason the window.document is loaded only with the Location attribute. Nothing more

Minimal reproduction case

import axios from 'axios';
import { JSDOM } from 'jsdom';

axios
    .get('https://gadget.horoscopovirtual.com.br/horoscopo/')
    .then((resp) => new JSDOM(resp.data))
    .then((website) => {
        console.log(website.window.document); // Document { location: [Getter/Setter] }
    });

I've checked the result of the axios request and it contains the html in string form. It should be ok, I've already done that before with the exact same code and it worked fine.

domenic commented 1 year ago

Please add code that behaves differently (e.g., x !== y) in browsers and Node. What shows up in the console is up to Node.js and browsers's UI teams.

TramontaG commented 1 year ago

What you mean by code that behaves differently? The console output is not the problem, the JSDOM object itself is missing everything but Location, logging to the console was just the way to verify that. All the other properties like querySelector, addEventListener, body and everything else are undefined when I try to access via code.

domenic commented 1 year ago

Please give me an example that shows website.window.document.body === undefined or similar. I think you'll find that prints false.