jsdom icon indicating copy to clipboard operation
jsdom copied to clipboard

getComputedStyle does not return live style CSSStyleDeclaration, but a static one

Open SubliemeSiem opened this issue 2 years ago • 2 comments

Basic info:

  • Node.js version: 16.16.0
  • jsdom version: 22.0.0

Minimal reproduction case

const { JSDOM } = require("jsdom");

const jsDom = new JSDOM(
    '',
    {
        url: "https://localhost",
        runScripts: "dangerously",
        pretendToBeVisual: true
    }
);
const window = jsDom.window;

const div = window.document.createElement('div');

window.document.body.appendChild(div);

const computedStyles = window.getComputedStyle(div);

console.log('before: ' + computedStyles.background);

div.style.setProperty('background', 'red');

console.log('after: ' + computedStyles.background);

result:

before: rgba(0, 0, 0, 0)
after: rgba(0, 0, 0, 0)

How does similar code behave in browsers?

In the browser, the "after" line shows an rgba for the red color as expected:

before: rgba(0, 0, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box
after: rgb(255, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box

Code pen: https://codepen.io/S-Peeters/pen/YzRzKem?editors=1111

SubliemeSiem avatar Jun 06 '23 09:06 SubliemeSiem

I also encountered a similar problem: before: red after: rgb(255, 0, 0)

Davont avatar Jun 19 '23 02:06 Davont

Same case here, the color (#ff0000, red) is always resolved to rgb format (rgb(255, 0, 0)).

juanrgm avatar Sep 24 '23 16:09 juanrgm