LanguageDetector: create() static method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The create() static method of the LanguageDetector interface creates a new LanguageDetector instance to detect languages.

Note: The create() method requires transient activation, that is, it must be invoked in response to a user action such as a mouse click or button press.

Syntax

js
LanguageDetector.create(options)

Parameters

options

An object specifying configuration options for the LanguageDetector. Possible values include:

expectedInputLanguages

An array of strings specifying the expected languages of the input text, which helps improve the accuracy of the language detection. These should be valid BCP 47 language tags. Defaults to ["en"].

monitor Optional

A callback function with a CreateMonitor argument that enables monitoring download progress of the AI model.

signal Optional

An AbortSignal object instance, which allows a create() operation to be aborted via the associated AbortController. The exact effect is dependant on when AbortController.abort() is called:

  • If abort() is called before the create() promise resolves, the create() operation is cancelled.
  • If abort() is called after the create() promise fulfills, it has the same effect as calling LanguageDetector.destroy(): The resources assigned to the resulting LanguageDetector instance are released, and any ongoing and subsequent LanguageDetector method calls will reject with an AbortError.

Return value

A Promise that fulfills with a LanguageDetector object instance.

Exceptions

InvalidStateError DOMException

Thrown if the page's Document is not yet active.

NetworkError DOMException

Thrown if:

  • The network was not available to download the AI model.
  • The user has cancelled the AI model download.
NotAllowedError DOMException

Thrown if:

NotSupportedError DOMException

Thrown if:

  • The language tags specified in expectedInputLanguages are invalid, or not supported.
  • An AI model to support the specified expectedInputLanguages is not available.
OperationError DOMException

General-purpose exception thrown if LanguageDetector creation failed for any other reason.

Examples

Basic LanguageDetector creation

js
const detector = await LanguageDetector.create({
  expectedInputLanguages: ["en-US", "zh"],
});

Specifications

Specification
Translator and Language Detector APIs
# dom-languagedetector-create

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
create() static method
Experimental
Chrome – Full support
Chrome 138 (Release date: 2025-06-24)
footnote
footnote Availability may be subject to geographical restrictions.
Edge – No support
Edge
footnote No support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 122 (Release date: 2025-09-11)
footnote
footnote Availability may be subject to geographical restrictions.
Safari – No support
Safari
footnote No support
Chrome Android – No support
Chrome Android
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – No support
WebView on iOS
footnote No support
Deno – No support
Deno
footnote No support
Node.js – No support
Node.js
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

See also