w3c / w3c/csswg-drafts

[cssom] Allow passing a callback to `window.getComputedStyle(…)`

Open
#3,579 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cssom-1
Dominant language
Bikeshed
Stars
4.9k
Forks
816
PR merge metrics
PR metrics pending

Description

https://drafts.csswg.org/cssom/#dom-window-getcomputedstyle

Right now, window.getComputedStyle(…) is always executed synchronously.

By allowing the last parameter to be a callback, this function could be made asynchronous in a backwards compatible manner.

interface Window {
    getComputedStyle(elt: Element, pseudoElt?: string | null): CSSStyleDeclaration;
    getComputedStyle(elt: Element, callback: (result: CSSStyleDeclaration) => void): void;
    getComputedStyle(elt: Element, pseudoElt: string | null, callback: (result: CSSStyleDeclaration) => void): void;
}

The following assertion holds true for legacy browsers:

// actual will only be undefined in modern browsers.
let actual = window.getComputedStyle(elt, function() {});
// expected will always be a CSSStyleDeclaration
let expected = window.getComputedStyle(elt);

// This works in legacy browsers:
assert.deepEqual(actual, expected);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the CSSOM getComputedStyle section at the linked specification URL and compare it with the proposed overloads in the issue. Determine the standards behavior and compatibility requirements for the callback form. Done means the Working Draft reflects an agreed callback API and its legacy-browser behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
css, javascript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.