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

Add HTMLImageElement.isTypeSupported() #10055

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

Conversation

annevk
Copy link
Member

@annevk annevk commented Jan 12, 2024

Give web developers a means to determine which formats are supported by the img element.

Fixes #6324.

  • At least two implementers are interested (and none opposed):
    • WebKit
  • Tests are written and can be reviewed and commented upon at:
  • Implementation bugs are filed:
    • Chromium: …
    • Gecko: …
    • WebKit: …
  • MDN issue is filed: …

(See WHATWG Working Mode: Changes for more details.)


/acknowledgements.html ( diff )
/embedded-content.html ( diff )
/images.html ( diff )

Give web developers a means to determine which formats are supported by the img element.

Fixes #6324.
@annevk annevk added needs implementer interest Moving the issue forward requires implementers to express interest needs tests Moving the issue forward requires someone to write tests labels Jan 12, 2024
<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>
Copy link
Member

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 &lt;a href="/wiki/Music_hall">music hall&lt;/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
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

@annevk annevk Jan 17, 2024

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
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs implementer interest Moving the issue forward requires implementers to express interest needs tests Moving the issue forward requires someone to write tests
Development

Successfully merging this pull request may close these issues.

Img: add method to check if image format is supported
3 participants