navigator.ml
The navigator.ml
property provides access to the WebNN API, allowing web applications to interact with machine learning capabilities in the browser.
Web IDL
web-idl
interface mixin NavigatorML {
[SecureContext, SameObject] readonly attribute ML ml;
};
Navigator includes NavigatorML;
WorkerNavigator includes NavigatorML;
Syntax
navigator.ml.js
const ml = navigator.ml
Value
An ML
object that provides access to WebNN functionality.
Description
The navigator.ml
property returns a read-only reference to an ML
object, which serves as the entry point for browser-based machine learning operations. This interface is:
- Available in both window and dedicated worker contexts
- Accessible through the
Navigator
interface in window contexts - Accessible through the
WorkerNavigator
interface in dedicated worker contexts - Protected by a secure context requirement (HTTPS or localhost)
Example
example.js
if ('ml' in navigator) {
// ML API is supported
const mlInstance = navigator.ml;
// Use ML functionality here
} else {
console.log('ML API is not supported in this browser');
}
Specifications
WebNN API | Status |
---|---|
navigator.ml interface | Candidate Recommendation Draft |
Security Requirements
Access to navigator.ml
requires a secure context (HTTPS or localhost). Attempting to access this API in a non-secure context will result in an error.
Browser Compatibility
The
navigator.ml
interface is experimental and support may vary across browsers.