recursal/MDN huggingface dataset:
WorkerNavigator: onLine property
================================

Returns the online status of the browser. The property returns a boolean value, with `true` meaning online and `false` meaning offline. The property sends updates whenever the browser's ability to connect to the network changes. The update occurs when the user follows links or when a script requests a remote page.

For example, the property should return `false` when users click links soon after they lose internet connection.

Browsers implement this property differently.

 In Chrome and Safari, if the browser is not able to connect to a local area network (LAN) or a router, it is offline; all other conditions return `true`. So while you can assume that the browser is offline when it returns a `false` value, you cannot assume that a true value necessarily means that the browser can access the internet. You could be getting false positives, such as in cases where the computer is running a virtualization software that has virtual ethernet adapters that are always
 "connected." Therefore, if you really want to determine the online status of the browser, you should develop additional means for checking. To learn more, see the 2011 article, Working Off the Grid.

In Firefox, switching the browser to offline mode sends a `false` value.

Value
-----

`online` is a boolean `true` or `false`.

Examples
--------

### Basic usage

To check if you are online in a worker, query `navigator.onLine`, as in the following example:


```js
if (navigator.onLine) {
  console.log("online");
} else {
  console.log("offline");
}
```


If the browser doesn't support `navigator.onLine` the above example will always come out as `false`/`undefined`.

### Listening for changes in network status

To see changes in the network state, use `addEventListener` to listen for the events on `online` and `offline`, as in the following example:


```js
addEventListener("offline", (e) => {
  console.log("offline");
});

addEventListener("online", (e) => {
  console.log("online");
});
```

Specifications
--------------

| Specification |
| --- |
| HTML Standard # dom-navigator-online-dev |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
WorkerNavigator: serviceWorker property
=======================================

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

The **`serviceWorker`** read-only property of the `WorkerNavigator` interface returns the `ServiceWorkerContainer` object for the associated document, which provides access to registration, removal, upgrade, and communication with the `ServiceWorker`.

The feature may not be available in private mode.

Value
-----

`ServiceWorkerContainer`.

Examples
--------

This code checks if the browser supports using service worker in workers.


```js
if ("serviceWorker" in navigator) {
  // Supported!
}
```

Specifications
--------------

| Specification |
| --- |
| Service Workers # navigator-serviceworker |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Service Worker API
* Using Service Workers
WorkerNavigator: languages property
===================================

 The **`WorkerNavigator.languages`** read-only property
 returns an array of strings representing the user's preferred
 languages. The language is described using language tags according to
 RFC 5646: Tags for Identifying Languages (also known as BCP 47). In the returned
 array they are ordered by preference with the most preferred language first.

 The value of `navigator.language` is the
 first element of the returned array.

 When its value changes, as the user's preferred languages are changed a
 `languagechange` event is fired on the `WorkerGlobalScope` object.

 The `Accept-Language` HTTP header in every HTTP request from the user's
 browser uses the same value for the `navigator.languages` property except for
 the extra `qvalues` (quality values) field (e.g. `en-US;q=0.8`).

Value
-----

An array or strings.

Examples
--------

You can run this insert a web worker:


```js
navigator.language; //"en-US"
navigator.languages; //["en-US", "zh-CN", "ja-JP"]
```

Specifications
--------------

| Specification |
| --- |
| HTML Standard # dom-navigator-languages-dev |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `WorkerNavigator.language`
* `WorkerNavigator`
* `languagechange` event
WorkerNavigator: appVersion property
====================================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

 Returns either "`4.0`" or a string representing version information about
 the browser.

**Note:** Do not rely on this property to return the correct browser version.

Value
-----

 Either "`4.0`" or a string representing version information about the
 browser.

Examples
--------


```js
alert(`Your browser version is reported as ${navigator.appVersion}`);
```

Notes
-----

 The `navigator.userAgent` property may also contain the version
 number (for example
 "`Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.2) Gecko/20010725 Netscape 6/6.1`"),
 but you should be aware of how easy it is to change the user agent string and "spoof"
 other browsers, platforms, or user agents, and also how cavalier the browser vendor
 themselves are with these properties.

 The `navigator.appVersion`, `navigator.appName` and
 `navigator.userAgent` properties have been used in "browser sniffing"
 code: scripts that attempt to find out what kind of browser you are using and adjust
 pages accordingly. This lead to the current situation, where browsers had to return fake
 values from these properties in order not to be locked out of some websites.

Specifications
--------------

| Specification |
| --- |
| HTML Standard # dom-navigator-appversion-dev |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
WorkerNavigator: platform property
==================================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

 Returns a string representing the platform of the browser. The specification allows
 browsers to always return the empty string, so don't rely on this property to get a
 reliable answer.

Value
-----

 A string identifying the platform on which the browser is running, or
 an empty string if the browser declines to (or is unable to) identify the platform.
 `platform` is a string that must be an empty string or a string representing
 the platform on which the browser is executing.

For example: "`MacIntel`", "`Win32`", "`FreeBSD i386`", "`WebTV OS`".

Examples
--------


```js
console.log(navigator.platform);
```

Usage notes
-----------

On Windows, modern browsers return `"Win32"` even if running on a 64-bit version of Windows

Specifications
--------------

| Specification |
| --- |
| HTML Standard # dom-navigator-platform-dev |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
WorkerNavigator: userAgent property
===================================

 The **`WorkerNavigator.userAgent`** read-only property returns the
 user agent string for the current browser.


**Note:** The specification asks browsers to provide as little information via this field as
 possible. Never assume that the value of this property will stay the same in future
 versions of the same browser. Try not to use it at all, or only for current and past
 versions of a browser. New browsers may start using the same UA, or part of it, as an
 older browser: you really have no guarantee that the browser agent is indeed the one
 advertised by this property.


 Also keep in mind that users of a browser can change the value of this field if they
 want (UA spoofing).


 Browser identification based on detecting the user agent string is
 **unreliable** and **is not recommended**, as the user agent
 string is user configurable. For example:

* In Firefox, you can change the preference `general.useragent.override` in
 `about:config`. Some Firefox extensions do that; however, this only changes
 the HTTP header that gets sent, and doesn't affect browser detection performed by
 JavaScript code.
* Opera 6+ allows users to set the browser identification string via a menu.
Value
-----

 A string specifying the complete user agent string the browser
 provides both in HTTP headers and in response to this and other related
 methods on the `WorkerNavigator` object.

 The user agent string is built on a formal structure which can be decomposed into
 several pieces of info. Each of these pieces of info comes from other navigator
 properties which are also settable by the user. Gecko-based browsers comply with the
 following general structure:
```

userAgent = appCodeName/appVersion number (Platform; Security; OS-or-CPU;
Localization; rv: revision-version-number) product/productSub
Application-Name Application-Name-version
```

Examples
--------


```js
alert(navigator.userAgent);
// alerts "Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.2) Gecko/20010725 Netscape6/6.1"
```

Specifications
--------------

| Specification |
| --- |
| HTML Standard # dom-navigator-useragent-dev |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `User-Agent` HTTP header
WorkerNavigator: language property
==================================

 The **`WorkerNavigator.language`** read-only property returns
 a string representing the preferred language of the user, usually the language of the
 browser UI.

Value
-----

 A string representing the
 language version as defined in RFC 5646: Tags for Identifying Languages (also known as BCP 47). Examples of valid language
 codes include "en", "en-US", "fr", "fr-FR", "es-ES", etc.

 Note that in Safari on iOS prior to 10.2, the country code returned is lowercase:
 "en-us", "fr-fr" etc.

Examples
--------

You can run this insert a web worker:


```js
if (/^en\b/.test(navigator.language)) {
  doLangSelect(window.navigator.language);
}
```

Specifications
--------------

| Specification |
| --- |
| HTML Standard # dom-navigator-language-dev |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `WorkerNavigator.languages`
* `WorkerNavigator`
WorkerNavigator: hardwareConcurrency property
=============================================

 The **`navigator.hardwareConcurrency`** read-only property
 returns the number of logical processors available to run threads on the user's
 computer.

Value
-----

A `Number` indicating the number of logical processor cores.

 Modern computers have multiple physical processor cores in their CPU (two or four cores
 is typical), but each physical core is also usually able to run more than one thread at
 a time using advanced scheduling techniques. So a four-core CPU may offer eight
 **logical processor cores**, for example. The number of logical processor
 cores can be used to measure the number of threads which can effectively be run at once
 without them having to context switch.

 The browser may, however, choose to report a lower number of logical cores in order to
 represent more accurately the number of `Worker`s that can run at once, so
 don't treat this as an absolute measurement of the number of cores in the user's system.

Examples
--------

 In this example, one `Worker` is created for each logical processor
 reported by the browser and a record is created which includes a reference to the new
 worker as well as a Boolean value indicating whether or not we're using that worker yet;
 these objects are, in turn, stored into an array for later use. This creates a pool of
 workers we can use to process requests later.

The following code can be run in a worker:


```js
let workerList = [];

for (let i = 0; i < navigator.hardwareConcurrency; i++) {
  let newWorker = {
    worker: new Worker("cpuworker.js"),
    inUse: false,
  };
  workerList.push(newWorker);
}
```

Specifications
--------------

| Specification |
| --- |
| HTML Standard # dom-navigator-hardwareconcurrency-dev |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `WorkerNavigator`
WorkerNavigator: storage property
=================================

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

 The **`storage`** read-only property of the `WorkerNavigator` interface
 returns the singleton `StorageManager` object used to
 access the overall storage capabilities of the browser for the current site or app.
 The returned object lets you examine and configure persistence of data stores and
 learn approximately how much more space your browser has available for local storage
 use.

Value
-----

 A `StorageManager` object you can use to maintain persistence for stored
 data, as well as to determine roughly how much room there is for data to be stored.

Specifications
--------------

| Specification |
| --- |
| Storage Standard # dom-navigatorstorage-storage |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `StorageManager`
* `WorkerNavigator`
WorkerNavigator: mediaCapabilities property
===========================================

 The read-only **`WorkerNavigator.mediaCapabilities`** property
 returns a `MediaCapabilities` object that can expose information about the
 decoding and encoding capabilities for a given format and output capabilities as defined
 by the Media Capabilities API.

Value
-----

A `MediaCapabilities` object.

Examples
--------


```js
navigator.mediaCapabilities
  .decodingInfo({
    type: "file",
    audio: {
      contentType: "audio/mp3",
      channels: 2,
      bitrate: 132700,
      samplerate: 5200,
    },
  })
  .then((result) => {
    console.log(
      `This configuration is ${result.supported ? "" : "not "}supported,`,
    );
    console.log(`${result.smooth ? "" : "not "}smooth, and`);
    console.log(`${result.powerEfficient ? "" : "not "}power efficient.`);
  });
```

Specifications
--------------

| Specification |
| --- |
| Media Capabilities # dom-workernavigator-mediacapabilities |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Media Capabilities API
* `WorkerNavigator`
WorkerNavigator: appName property
=================================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

 The value of the **`WorkerNavigator.appName`** property is always
 "`Netscape`", in any browser. This property is kept only for compatibility
 purposes.

**Note:** Do not rely on this property to return a real browser name. All browsers return "`Netscape`" as the value of this property.

Value
-----

The string "`Netscape`".

Specifications
--------------

| Specification |
| --- |
| HTML Standard # dom-navigator-appname-dev |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `WorkerNavigator.appCodeName`
* `WorkerNavigator.product`
WorkerNavigator: product property
=================================

**Deprecated:** This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

 The value of the **`WorkerNavigator.product`** property is always
 "`Gecko`", in any browser. This property is kept only for compatibility
 purposes.

**Note:** Do not rely on this property to return a real product name. All browsers return "`Gecko`" as the value of this property.

Value
-----

The string "`Gecko`".

Specifications
--------------

| Specification |
| --- |
| HTML Standard # dom-navigator-product-dev |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `WorkerNavigator.appCodeName`
* `WorkerNavigator.appName`
WorkerNavigator: clearAppBadge() method
=======================================

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

The **`clearAppBadge()`** method of the `WorkerNavigator` interface clears a badge on the current app's icon by setting it to `nothing`. The value `nothing` indicates that no badge is currently set, and the status of the badge is *cleared*.

Syntax
------


```js
clearAppBadge()
```

### Parameters

None.

### Return value

A `Promise` that resolves with `undefined`.

### Exceptions

`InvalidStateError` `DOMException`

Thrown if the document is not fully active.

`SecurityError` `DOMException`

Thrown if the call was blocked by the same-origin policy.

`NotAllowedError` `DOMException`

Thrown if `PermissionStatus.state` is not `granted`.

Examples
--------

Once all messages in an application have been read, call `clearAppBadge()` to clear the badge and remove the notification.


```js
navigator.clearAppBadge();
```

Specifications
--------------

#### No specification found

No specification data found for `api.WorkerNavigator.clearAppBadge`.  
Check for problems with this page or contribute a missing `spec_url` to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Badging for app icons
WorkerNavigator: connection property
====================================

 The **`WorkerNavigator.connection`** read-only property returns
 a `NetworkInformation` object containing information about the system's
 connection, such as the current bandwidth of the user's device or whether the connection
 is metered. This could be used to select high definition content or low definition
 content based on the user's connection.

Value
-----

A `NetworkInformation` object.

Specifications
--------------

| Specification |
| --- |
| Network Information API # connection-attribute |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Online and offline events
* Network Information API
NavigationPreloadManager: enable() method
=========================================

 The **`enable()`** method of the `NavigationPreloadManager` interface is used to enable preloading of resources managed by the service worker.
 It returns a promise that resolves with `undefined`.

The method should be called in the service worker's `activate` event handler, which ensures it is called before any `fetch` event handler can fire.

Syntax
------


```js
enable()
```

### Parameters

None.

### Return value

A `Promise` that resolves with `undefined`.

### Exceptions

`InvalidStateError` `DOMException`

There is no active worker associated with the registration to which this `NavigationPreloadManager` belongs.

Examples
--------

The code below shows how to enable preloading, after first using `ServiceWorkerRegistration.navigationPreload` to test that it is supported.


```js
addEventListener("activate", (event) => {
  event.waitUntil(
    (async () => {
      if (self.registration.navigationPreload) {
        // Enable navigation preloads!
        await self.registration.navigationPreload.enable();
      }
    })(),
  );
});
```

Specifications
--------------

| Specification |
| --- |
| Service Workers # dom-navigationpreloadmanager-enable |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

`NavigationPreloadManager.disable()`
NavigationPreloadManager: setHeaderValue() method
=================================================

 The **`setHeaderValue()`** method of the `NavigationPreloadManager` interface sets the value of the `Service-Worker-Navigation-Preload` header that will be sent with requests resulting from a `fetch()` operation made during service worker navigation preloading.
 It returns an empty `Promise` that resolves with `undefined`.

 The presence of the `Service-Worker-Navigation-Preload` header in preloading requests allows servers to configure the returned resource differently for preloading fetch requests than from normal fetch requests.
 The default directive is set to `true`: this method allows the possibility of configuring multiple different responses to preload requests.

**Note:** If a different response may result from setting this header, the server must set `Vary: Service-Worker-Navigation-Preload` to ensure that the different responses are cached.

Syntax
------


```js
setHeaderValue(value)
```

### Parameters

`value`

An arbitrary string value, which the target server uses to determine what should returned for the requested resource.

### Return value

A `Promise` that resolves with `undefined`.

### Exceptions

`InvalidStateError` `DOMException`

There is no active worker associated with the registration to which this `NavigationPreloadManager` belongs.

Examples
--------

The code below demonstrates how the value might be set.


```js
navigator.serviceWorker.ready
  .then((registration) =>
    registration.navigationPreload.setHeaderValue(newValue),
  )
  .then(() => console.log("Done!"))
  .catch((e) =>
    console.error(`NavigationPreloadManager not supported: ${e.message}`),
  );
```

Specifications
--------------

| Specification |
| --- |
| Service Workers # dom-navigationpreloadmanager-setheadervalue |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.