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.
LanguageDetector.create(options)
optionsAn object specifying configuration options for the LanguageDetector. Possible values include:
expectedInputLanguagesAn 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 (as specified in RFC 5646). Defaults to ["en"].
monitor OptionalA callback function with a CreateMonitor argument that enables monitoring download progress of the AI model.
signal OptionalAn AbortSignal object instance, which allows the create() operation to be aborted via the associated AbortController.
A Promise that fulfills with a LanguageDetector object instance.
InvalidStateError DOMException
Thrown if the page's Document is not yet active.
NetworkError DOMException
Thrown if:
NotAllowedError DOMException
Thrown if:
language-detector Permissions-Policy.create() method wasn't called via transient activation.NotSupportedError DOMException
Thrown if:
expectedInputLanguages are invalid, or not supported.expectedInputLanguages is not available.OperationError DOMException
General-purpose exception thrown if LanguageDetector creation failed for any other reason.
LanguageDetector creationconst detector = await LanguageDetector.create({
expectedInputLanguages: ["en-US", "zh"],
});
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
create_static |
138Availability may be subject to geographical restrictions. |
No | No | 122Availability may be subject to geographical restrictions. |
No | No | No | No | No | No | No | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/LanguageDetector/create_static