Skip to content

[cssom] Throwing on invalid pseudo-elements in getComputedStyle is not web-compatible #6501

@emilio

Description

@emilio

I tried to implement the resolution from #2149 in Firefox, and we instantly found broken pages because of that.

There are two patterns that show up:

  • getComputedStyle(something, "height"); (or any other property instead of height). Seems like a coding error on the given site, but all browsers agree on not throwing there.
  • getComputedStyle(something, false); (which per WebIDL rules gets turned into getComputedStyle(something, "false");). This is also an error (because the right thing to use if you want to be explicit about the argument is null, not false), but it seems throwing there is more harmful than good.

So I propose we need to at least not throw when the string doesn't start with a colon. All browsers agree on returning the non-pseudo-element style there, so I suggest to just spec reality there.

For the cases the string does start with a colon we could:

  • Try to throw (I can come back with data).
  • Not throw, returning the non-pseudo-element style instead (WebKit / Blink behavior): It is consistent with the "string doesn't begin with a colon" case, but it seems a bit unfortunate.
  • Not throw, returning an empty style (length = 0) (Firefox behavior).

I think I prefer the third but I'd love to hear opinions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions