-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add HTMLImageElement.isTypeSupported() #10055
base: main
Are you sure you want to change the base?
Conversation
Give web developers a means to determine which formats are supported by the img element. Fixes #6324.
<p>This specification does not specify which image types are to be supported.</p> | ||
<p>A user agent has an associated <dfn>supported image MIME types</dfn> (a <span>set</span> of | ||
<span data-x="MIME type">MIME types</span>). A user agent's <span>supported image MIME | ||
types</span> is <span>implementation-defined</span>.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth double-checking there aren't places in "update the image data" that would benefit from direct references to this concept. E.g. maybe step 2? Or maybe the indirect reference in step 27 should be more direct? Not sure though.
@@ -30488,7 +30531,9 @@ was an English <a href="/wiki/Music_hall">music hall</a> singer, ...</code | |||
of a multipage resource (e.g. a PDF file). User agents must not allow the resource to act in an | |||
interactive fashion, but should honour any animation in the resource.</p> | |||
|
|||
<p>This specification does not specify which image types are to be supported.</p> | |||
<p>A user agent has an associated <dfn>supported image MIME types</dfn> (a <span>set</span> of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can/should we be less implementation-defined for the case of a user agent with images disabled? Chrome still lets you toggle images for a site pretty easily using the site settings button accessed from the URL bar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would be good, but do we have a processing model for images being disabled? https://html.spec.whatwg.org/#when-to-obtain-images suggests that images are either obtained immediately or on demand, but doesn't allow for them to be completely disabled. The specification model at least suggests to me that the supported image MIME type situation wouldn't change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://html.spec.whatwg.org/#update-the-image-data step 2 seems like a reasonable processing model for images disabled. Not sure how battle-tested it is.
|
||
<li><p>If <var>mimeTypeRecord</var> is in the user agent's <span>supported image MIME | ||
types</span> (and the user agent thus recognizes the <span data-x="MIME type | ||
essence">essence</span> and all parameters (if any)), set <var>supported</var> to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure exactly how parameter matching is supposed to work. Let's say a UA supports image/foo
with the bar
parameter set to any value. The MIME type record you get from parsing image/foo;bar=baz
is not literally going to be in the set. (Unless the set is infinite in size; I guess in theory that's allowed.)
It feels like the "supported image MIME types" structure needs to get more complicated, to handle this sort of case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, how about a map of MIME type essences to lists of parameter names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that would solve my example, but what about if the UA supports image/foo;bar=X
but only X
? :)
I think it might be best to just have a UA-defined "supports image MIME type mimeType" predicate, which takes a MIME type and returns a boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. I guess we do want some words to make it so that unknown parameters or parameter values result in non-support.
@@ -29217,9 +29219,17 @@ interface <dfn interface>HTMLImageElement</dfn> : <span>HTMLElement</span> { | |||
</div> | |||
|
|||
<dl class="domintro"> | |||
<dt><code data-x=""><var>supported</var> = await <span>HTMLImageElement</span>.<span subdfn data-x="dom-img-isTypeSupported">isTypeSupported</span>(<var>mimeType</var>)</code></dt> | |||
<dd> | |||
<p>Returns a promise resolved with true, if <var>mimeType</var> is supported for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth linking "supported" to "supported image MIME types" here, just as helpful link for devs?
Give web developers a means to determine which formats are supported by the img element.
Fixes #6324.
(See WHATWG Working Mode: Changes for more details.)
/acknowledgements.html ( diff )
/embedded-content.html ( diff )
/images.html ( diff )