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

runScripts: 'dangerously' changes the output of Object.getOwnPropertyNames(jsdom.window) #3688

Open
DanKaplanSES opened this issue Mar 1, 2024 · 0 comments

Comments

@DanKaplanSES
Copy link
Contributor

DanKaplanSES commented Mar 1, 2024

Basic info:

  • Node.js version: 20.10.0
  • jsdom version: 24.0.0 (I saw no difference in v22)

Minimal reproduction case

import { JSDOM } from 'jsdom';

const { window } = new JSDOM('', {
    url: 'http://localhost',
    runScripts: 'dangerously',
    resources: 'usable',
    pretendToBeVisual: true,
})

console.log(`Object.getOwnPropertyNames(window).filter((k) => k === "HTMLElement").length`, 
    Object.getOwnPropertyNames(window).filter((k) => k === "HTMLElement").length); // 0

How does similar code behave in browsers?

console.log(`Object.getOwnPropertyNames(window).filter((k) => k === "HTMLElement").length`, 
    Object.getOwnPropertyNames(window).filter((k) => k === "HTMLElement").length); // 1

Additional information

  1. I've yet to understand why, but the runScripts: 'dangerously', is causing this problem. When I comment that out, the console.log prints 1, just like a browser.

  2. I created this StackOverflow question before creating this issue. It might provide some helpful context, and it includes additional log statements showing similarities between the two environments. For example, window.HTMLElement have equivalent property descriptors in both.

    I don't fully understand the ramifications of these differences, but it made it challenging to troubleshoot the JSDOM error I was experiencing at the bottom of that SO example.

  3. I tested this in Firefox and Google Chrome and both print 1.

@DanKaplanSES DanKaplanSES changed the title Browsers return DOM property names in Object.getOwnPropertyNames(window). JSDOM does not. Object.getOwnPropertyNames(window) returns DOM property names in browsers. JSDOM does not. Mar 1, 2024
@DanKaplanSES DanKaplanSES changed the title Object.getOwnPropertyNames(window) returns DOM property names in browsers. JSDOM does not. Object.getOwnPropertyNames(window) returns DOM property names in browsers. Object.getOwnPropertyNames(jsdom.window) does not. Mar 1, 2024
@DanKaplanSES DanKaplanSES changed the title Object.getOwnPropertyNames(window) returns DOM property names in browsers. Object.getOwnPropertyNames(jsdom.window) does not. runScripts: 'dangerously' changes the output of Object.getOwnPropertyNames(jsdom.window) Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant