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

Trusted Types - FF updates and missing entries in TT spec #25839

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

hamishwillee
Copy link
Contributor

@hamishwillee hamishwillee commented Feb 3, 2025

FF has added more support for trusted types behind a flag. This adds those updates.

Also it adds some missing entries, primarily for the methods and properties that will now accept trusted types. Some of this is a bit weird so I've added comments inline explaining how/why I did stuff.

The spec mentions some other cases such as Element.outerHTML setters, and functions that create a new same-origin Document with caller-controlled markup like parseFromString(). Have not added that, because I haven't tested it.

@github-actions github-actions bot added data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API size:l [PR only] 101-1000 LoC changed labels Feb 3, 2025
"status": {
"experimental": false,
"standard_track": true,
"deprecated": true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this is set as not experimental and deprecated, because the parent is deprecated (and you can't have both set).

@@ -417,6 +417,53 @@
}
}
},
"innerText": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for this one (and textContent), the properties were around since forever, but inherited. Since this update only applies to the HTMLScriptElement I have added it here as though it were a new property.

Is this OK? I mean it looks like you can only access this from current version, which might be confusing to readers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be confusing, yes, because innerText is also defined and BCD-ified in the parent HTMLElement: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement#browser_compatibility.

And the innerText page takes its BCD from there: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText#browser_compatibility so this change won't even show up in that page.

Maybe instead of this, add a subfeature to HTMLElement.innerText, like: "Script elements can accept a TrustedScript"? Then it will show up as a subfeature in https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText#browser_compatibility .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on how important strict following of IDL is for BCD. I like the idea though - changed in df3f74f

@@ -14,7 +14,14 @@
"chrome_android": "mirror",
"edge": "mirror",
"firefox": {
"version_added": false,
"version_added": "135",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure when this became useful. The whole API was added behind pref in 125 and no implementation. I've put 135 because it does not harm and we're starting to get where tests can be useful.

@hamishwillee hamishwillee marked this pull request as ready for review February 3, 2025 06:16
api/Element.json Outdated
@@ -6263,6 +6263,53 @@
"standard_track": true,
"deprecated": false
}
},
"accepts_TrustedHtml": {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for other cases, you can set the property with this, but if you were to get it back you'd get a string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I wonder if there would be any desire to formalize BCD subfeatures for property getters and setters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be good. For now I have tried to be consistent.

Copy link
Contributor

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Elchi3 asked me for a "domain review" of this PR :).

},
"text_param_accepts_TrustedHTML": {
"__compat": {
"description": "`text` parameter accepts `TrustedHTML` type",
Copy link
Contributor

@wbamberg wbamberg Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The page calls the parameter markup so this will be confusing. Also IDK if anyone cares but I think strictly, the parameter doesn't "accept" anything - it is the function that accepts things. The parameter just is something.

Since this method only accepts one parameter we might not have to name the parameter and say "Accepts a TrustedHTML instance" or something like that.

Copy link
Contributor Author

@hamishwillee hamishwillee Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, changed to:

        "accepts_TrustedHTML": {
          "__compat": {
            "description": "Accepts `TrustedHTML` instances",

This takes an arbitrary number of either/both strings or trusted HTML instances.

FYI I also changed this in my docs PR to text, but will revert, as markup is a better term.

api/Document.json Outdated Show resolved Hide resolved
api/Element.json Outdated
@@ -6263,6 +6263,53 @@
"standard_track": true,
"deprecated": false
}
},
"accepts_TrustedHtml": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I wonder if there would be any desire to formalize BCD subfeatures for property getters and setters.

@@ -417,6 +417,53 @@
}
}
},
"innerText": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be confusing, yes, because innerText is also defined and BCD-ified in the parent HTMLElement: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement#browser_compatibility.

And the innerText page takes its BCD from there: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText#browser_compatibility so this change won't even show up in that page.

Maybe instead of this, add a subfeature to HTMLElement.innerText, like: "Script elements can accept a TrustedScript"? Then it will show up as a subfeature in https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText#browser_compatibility .

api/HTMLScriptElement.json Outdated Show resolved Hide resolved
api/HTMLScriptElement.json Outdated Show resolved Hide resolved
api/ShadowRoot.json Outdated Show resolved Hide resolved
api/_globals/setInterval.json Outdated Show resolved Hide resolved
api/_globals/setInterval.json Outdated Show resolved Hide resolved
api/Element.json Outdated Show resolved Hide resolved
api/ShadowRoot.json Outdated Show resolved Hide resolved
api/Element.json Outdated Show resolved Hide resolved
@hamishwillee hamishwillee requested a review from wbamberg February 7, 2025 00:29
@hamishwillee
Copy link
Contributor Author

@wbamberg Thanks. Accepted all your suggestions - ready for another look

api/Document.json Show resolved Hide resolved
api/Document.json Outdated Show resolved Hide resolved
api/Document.json Outdated Show resolved Hide resolved
Comment on lines 9039 to 9040
"mdn_url": "https://developer.mozilla.org/docs/Web/API/Document/writeln",
"spec_url": "https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-writeln",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito (see above)

api/Document.json Outdated Show resolved Hide resolved
],
"support": {
"chrome": {
"version_added": "83"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito (etc)

api/_globals/setInterval.json Outdated Show resolved Hide resolved
api/_globals/setTimeout.json Outdated Show resolved Hide resolved
Co-authored-by: Claas Augner <495429+caugner@users.noreply.github.com>
api/Document.json Outdated Show resolved Hide resolved
api/Document.json Outdated Show resolved Hide resolved
api/Element.json Outdated Show resolved Hide resolved
],
"support": {
"chrome": {
"version_added": "83"
Copy link
Contributor Author

@hamishwillee hamishwillee Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping this as 83 - based on this test in browserstack passing in that version https://wpt.live/trusted-types/HTMLElement-generic.html

],
"support": {
"chrome": {
"version_added": "83"
Copy link
Contributor Author

@hamishwillee hamishwillee Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

],
"support": {
"chrome": {
"version_added": "83"
Copy link
Contributor Author

@hamishwillee hamishwillee Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping as 83 based on TT being allowed in that version https://wpt.live/trusted-types/trusted-types-reporting-for-HTMLScriptElement.html (other tests fail, but not that one)

api/ShadowRoot.json Outdated Show resolved Hide resolved
Co-authored-by: Claas Augner <495429+caugner@users.noreply.github.com>
@hamishwillee hamishwillee requested a review from caugner February 9, 2025 22:49
@hamishwillee
Copy link
Contributor Author

Thanks @caugner ! I've accepted your comments, and removed a few more cases of mdn URLs in the "accept" features (i.e. "dittos")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API size:l [PR only] 101-1000 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants