Skip to content

[cssom-1] Serializing via cssText doesn't give url(<string>) #9913

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

Open
gsnedders opened this issue Feb 5, 2024 · 1 comment
Open

[cssom-1] Serializing via cssText doesn't give url(<string>) #9913

gsnedders opened this issue Feb 5, 2024 · 1 comment
Labels
cssom-1 Current Work

Comments

@gsnedders
Copy link
Member

From https://bugs.webkit.org/show_bug.cgi?id=268742:

const style = document.createElement('style')
document.body.append(style)
style.sheet.insertRule(`h6 {
    background: url(/my-image.png), var(--my-image);
}`)
console.log(style.sheet.cssRules[0].cssText)

Safari outputs:

h6 { background: url(\/my-image\.png), var(--my-image); }

Chrome and Firefox outputs:

h6 { background: url(/my-image.png), var(--my-image); }

Per spec, cssText returns "a serialization of the CSS rule".

A URL is serialized as '"url(", followed by the serialization of the URL as a string, followed by ")"', which implies the above should be url("/my-image.png"), contrary to all major browsers.

@gsnedders gsnedders added the cssom-1 Current Work label Feb 5, 2024
@cdoublev
Copy link
Collaborator

cdoublev commented Feb 5, 2024

If I am not mistaken, Chrome and FF serialize the original input string for values containing arbitrary substitutions like var() (cf. #6484).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cssom-1 Current Work
Projects
None yet
Development

No branches or pull requests

2 participants