Skip to content

Introduce async TextDetector create and availability methods#110

Merged
reillyeon merged 2 commits intoWICG:mainfrom
alvinjiooo:async_creation
Feb 25, 2026
Merged

Introduce async TextDetector create and availability methods#110
reillyeon merged 2 commits intoWICG:mainfrom
alvinjiooo:async_creation

Conversation

@alvinjiooo
Copy link
Contributor

This change introduces two new static methods to the TextDetector interface:

  • TextDetector.availability(options): Allows developers to quickly check if a given set of languages are supported for text detection.
  • TextDetector.create(options): A promise-based factory method that handles asynchronous resource setup and returns a TextDetector instance.

This fixes #109

text.bs Outdated
SecureContext
] interface TextDetector {
constructor();
static Promise<sequence<DOMString>> availability(TextDetectorOptions options);
Copy link
Collaborator

Choose a reason for hiding this comment

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

To match the design of the Writing Assistance APIs as described in #109 this should return Availability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking that sequence<DOMString> is sufficient to indicate available/not available state when we pass sequence<DOMString> languages in TextDetectorOptions. How about return sequence<Availability> so it can check multiple language in one go? Or should we change it as availability(DOMString language) to take one language at a time. WDYT?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right now we don't have a pattern for enumerating the set of all supported languages for an API like Translator or Summarizer. I'd rather be consistent with the other APIs and solve the problem of answering the question of "what languages are supported by this client" separately.

The current shape of Translator.availability() for example is good enough because when the developer is looking to translate some text they know what language it's in, though there might be cases where for the UI they are trying to display it would be useful to enumerate all possible languages that the client supports.

Given that it's useful for a TextDetector to be configured to detect multiple languages at a time (e.g. for a multi-lingual document) it makes sense to keep the current input parameter shape, but return a single Availability for consistency with the other APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for suggestion! I updated it to reuse Availability from writing-assistance-apis. Please review the latest patch. Thanks!

@alvinjiooo
Copy link
Contributor Author

@reillyeon, thanks for review and approval.
For some reason I am seeing the "Build, Validate and Deploy" is pending and it shows "1 workflow awaiting approval". That seems require you (maintainer) to approve too.

@reillyeon reillyeon merged commit 95dda25 into WICG:main Feb 25, 2026
2 checks passed
github-actions bot added a commit that referenced this pull request Feb 25, 2026
SHA: 95dda25
Reason: push, by reillyeon

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions bot added a commit that referenced this pull request Feb 25, 2026
SHA: 95dda25
Reason: push, by reillyeon

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@alvinjiooo alvinjiooo deleted the async_creation branch February 25, 2026 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[text-detection] Supporting asynchronous initialization for TextDetector

2 participants