recursal/MDN huggingface dataset:
WorkerGlobalScope: securitypolicyviolation event
================================================

The **`securitypolicyviolation`** event is fired when a Content Security Policy is violated in a worker.

The handler can be assigned using the `onsecuritypolicyviolation` event handler property or using `EventTarget.addEventListener()`.

Syntax
------

Use the event name in methods like `addEventListener()`, or set an event handler property.


```js
addEventListener("securitypolicyviolation", (event) => {});

onsecuritypolicyviolation = (event) => {};
```

Event type
----------

A `SecurityPolicyViolationEvent`. Inherits from `Event`.

Event

SecurityPolicyViolationEventExamples
--------

The code below shows how you might add an event handler function using the `onsecuritypolicyviolation` event handler property or call `addEventListener()` method.


```js
self.onsecuritypolicyviolation = (e) => {
  // Handle SecurityPolicyViolationEvent e here
};

self.addEventListener("securitypolicyviolation", (e) => {
  // Handle SecurityPolicyViolationEvent e here
});
```

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

| Specification |
| --- |
| Content Security Policy Level 3 # eventdef-globaleventhandlers-securitypolicyviolation |

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

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

See also
--------

* The `securitypolicyviolation` event of the `Document` interface
* The `securitypolicyviolation` event of the `Element` interface
* HTTP > Content Security Policy
WorkerGlobalScope: importScripts() method
=========================================

The **`importScripts()`** method of the `WorkerGlobalScope` interface synchronously imports one or more scripts into the worker's scope.

Syntax
------


```js
importScripts(path0)
importScripts(path0, path1)
importScripts(path0, path1, /\* …, \*/ pathN)
```

### Parameters

`pathN`

A string value representing the URL of the script to be imported. The URL may be absolute or relative. If the URL is relative, it is relative to the HTML document's base URL.

### Return value

None (`undefined`).

### Exceptions

`NetworkError`

Imported scripts were served without a `text/javascript` MIME type or without one of the permitted legacy JavaScript MIME types.

Examples
--------

If you had some functionality written in a separate script called `foo.js` that you wanted to use inside worker.js, you could import it using the following line:


```js
importScripts("foo.js");
```


`importScripts()` and `self.importScripts()` are effectively equivalent — both represent `importScripts()` being called from inside the worker's inner scope.

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

| Specification |
| --- |
| HTML Standard # dom-workerglobalscope-importscripts-dev |

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

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

See also
--------

* `WorkerGlobalScope`
WorkerGlobalScope: navigator property
=====================================

The **`navigator`** read-only property of the `WorkerGlobalScope` interface returns the `WorkerNavigator` associated with the worker. It is a specific navigator object, mostly a subset of the `Navigator` for browsing scopes, but adapted to workers.

Value
-----

A `WorkerNavigator` object.

Examples
--------

If you call the following


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


inside a worker (which would basically be the equivalent of `self.console.log(self.navigator);`, as these are being called on the worker scope, which can be referenced with `WorkerGlobalScope.self`), you will get a `WorkerNavigator` object written to the console — something like the following:
```

Object {onLine: true, userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) Ap…ML, like Gecko) Chrome/40.0.2214.93 Safari/537.36", product: "Gecko", platform: "MacIntel", appVersion: "5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKi…ML, like Gecko) Chrome/40.0.2214.93 Safari/537.36"…}
    appCodeName: "Mozilla"
    appName: "Netscape"
    appVersion: "5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36"
    hardwareConcurrency: 4
    onLine: true
    platform: "MacIntel"
    product: "Gecko"
    userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36"
    __proto__: Object
```


You could use this navigator object to return more information about the runtime environment, as you might do with a normal `Navigator` object.

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

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

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

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

See also
--------

`WorkerNavigator`
WorkerGlobalScope: dump() method
================================

**Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

**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 **`WorkerGlobalScope.dump()`** method logs messages to the browser's standard output (`stdout`). If the browser was started from a terminal, output sent to `dump()` will appear in the terminal. This is the same as `Window.dump()`, but for workers.

Output from `dump()` is *not* sent to the browser's developer tools console. To log to the developer tools console, use `console.log()`.

Syntax
------


```js
dump(message)
```

### Parameters

`message`

A string containing the message to log.

### Return value

None (`undefined`).

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

This feature is not part of any specification.

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

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.
WorkerGlobalScope: offline event
================================

The **`offline`** event of the `WorkerGlobalScope` fires when the device loses connection to the internet.

Syntax
------

Use the event name in methods like `addEventListener()`, or set an event handler property.


```js
addEventListener("offline", (event) => {});

onoffline = (event) => {};
```

Event type
----------

A generic `Event`.

Example
-------

The following code snippet shows an `onoffline` handler set inside a worker:


```js
self.onoffline = () => {
  console.log("Your worker is now offline");
};
```


The same snippet, but using `addEventListener()`:


```js
self.addEventListener("offline", () => {
  console.log("Your worker is now offline");
});
```

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

| Specification |
| --- |
| HTML Standard # handler-workerglobalscope-onoffline |

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

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

See also
--------

The `WorkerGlobalScope` interface it belongs to.
WorkerGlobalScope: location property
====================================

The **`location`** read-only property of the `WorkerGlobalScope` interface returns the `WorkerLocation` associated with the worker. It is a specific location object, mostly a subset of the `Location` for browsing scopes, but adapted to workers.

Value
-----

A `WorkerLocation` object.

Examples
--------

If you called the following in a document served at `localhost:8000`


```js
console.log(location);
```


inside a worker (which would basically be the equivalent of `self.console.log(self.location);`, as these are being called on the worker scope, which can be referenced with `WorkerGlobalScope.self`), you will get a `WorkerLocation` object written to the console — something like the following:
```

WorkerLocation {hash: "", search: "", pathname: "/worker.js", port: "8000", hostname: "localhost"…}
  hash: ""
  host: "localhost:8000"
  hostname: "localhost"
  href: "http://localhost:8000/worker.js"
  origin: "http://localhost:8000"
  pathname: "/worker.js"
  port: "8000"
  protocol: "http:"
  search: ""
  __proto__: WorkerLocation
```


You could use this location object to return more information about the document's location, as you might do with a normal `Location` object.

**Note:** Firefox has a bug with using `console.log` inside shared/service workers (see Firefox bug 1058644), which may return strange results, but this should be fixed soon.

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

| Specification |
| --- |
| HTML Standard # dom-workerglobalscope-location-dev |

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

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

See also
--------

`WorkerGlobalScope`
WorkerGlobalScope: self property
================================

The **`self`** read-only property of the `WorkerGlobalScope` interface returns a reference to the `WorkerGlobalScope` itself. Most of the time it is a specific scope like `DedicatedWorkerGlobalScope`, `SharedWorkerGlobalScope`, or `ServiceWorkerGlobalScope`.

Value
-----

A global scope object (differs depending on the type of worker you are dealing with, as indicated above).

Examples
--------

If you called


```js
console.log(self);
```


inside a worker, you will get a worker global scope of the same type as that worker object written to the console — something like the following:
```

DedicatedWorkerGlobalScope {
undefined: undefined, Infinity: Infinity, Math: MathConstructor, NaN: NaN, Intl: Object…}
    Infinity: Infinity
    Array: function Array() { [native code] }
      arguments: null
      caller: null
      isArray: function isArray() { [native code] }
      length: 1
      name: "Array"
      observe: function observe() { [native code] }
      prototype: Array[0]
      unobserve: function unobserve() { [native code] }
      __proto__: function Empty() {}
      <function scope>
    ArrayBuffer: function ArrayBuffer() { [native code] }
    Blob: function Blob() { [native code] }
    Boolean: function Boolean() { [native code] }
    DataView: function DataView() { [native code] }
    Date: function Date() { [native code] }
    DedicatedWorkerGlobalScope: function DedicatedWorkerGlobalScope() { [native code] }
    Error: function Error() { [native code] }
// etc. etc.
```


This provides a full list of the objects available to that worker scope, so it is quite a useful test if you want to see whether something is available to your worker or not. We also maintain a list of Functions and classes available to Web Workers.

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

| Specification |
| --- |
| HTML Standard # dom-workerglobalscope-self-dev |

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

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

See also
--------

`WorkerGlobalScope`
WorkerGlobalScope: unhandledrejection event
===========================================

The **`unhandledrejection`** event is sent to the global scope (typically `WorkerGlobalScope`) of a script when a `Promise` that has no rejection handler is rejected.

This is useful for debugging and for providing fallback error handling for unexpected situations.

Syntax
------

Use the event name in methods like `addEventListener()`, or set an event handler property.


```js
self.addEventListener("unhandledrejection", (event) => {});
self.onunhandledrejection = (event) => {};
```

Event type
----------

A `PromiseRejectionEvent`. Inherits from `Event`.

Event

PromiseRejectionEventEvent properties
----------------

`PromiseRejectionEvent.promise` Read only 

The JavaScript `Promise` that was rejected.

`PromiseRejectionEvent.reason` Read only 

A value or `Object` indicating why the promise was rejected, as passed to `Promise.reject()`.

Examples
--------

### Basic error logging

This example logs information about the unhandled promise rejection to the console.


```js
self.addEventListener("unhandledrejection", (event) => {
  console.warn(`UNHANDLED PROMISE REJECTION: ${event.reason}`);
});
```


You can also use the `onunhandledrejection` event handler property to set up the event listener:


```js
self.onunhandledrejection = (event) => {
  console.warn(`UNHANDLED PROMISE REJECTION: ${event.reason}`);
};
```

### Preventing default handling

Many environments (such as Node.js) report unhandled promise rejections to the console by default. You can prevent that from happening by adding a handler for `unhandledrejection` events that—in addition to any other tasks you wish to perform—calls `preventDefault()` to cancel the event, preventing it from bubbling up to be handled by the runtime's logging code. This works because `unhandledrejection` is cancelable.


```js
self.addEventListener("unhandledrejection", (event) => {
  // code for handling the unhandled rejection
  // …

  // Prevent the default handling (such as outputting the
  // error to the console)

  event.preventDefault();
});
```

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

#### No specification found

No specification data found for `api.WorkerGlobalScope.unhandledrejection_event`.  
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
--------

* Promise rejection events
* `PromiseRejectionEvent`
* `Promise`
* `rejectionhandled` event
WorkerGlobalScope: fonts property
=================================

The **`fonts`** property of the `WorkerGlobalScope` interface returns the `FontFaceSet` interface of the worker.

This property is part of the CSS Font Loading API.

Value
-----

 The returned value is the `FontFaceSet` interface of the worker.
 The `FontFaceSet` interface is useful for loading new fonts, checking the status of previously loaded fonts etc.

Examples
--------

### Doing operation after all fonts are loaded


```js
fonts.ready.then(() => {
  // Any operation that needs to be done only after all the fonts
  // have finished loading can go here.
});
```

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

| Specification |
| --- |
| CSS Font Loading Module Level 3 # dom-fontfacesource-fonts |

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

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

See also
--------

* `FontFaceSet` interface
* `FontFace`
WorkerGlobalScope: rejectionhandled event
=========================================

The **`rejectionhandled`** event is sent to the script's global scope (typically `WorkerGlobalScope`) whenever a rejected `Promise` is handled late, i.e., when a handler is attached to the promise after its rejection had caused an `unhandledrejection` event.

This can be used in debugging and for general application resiliency, in tandem with the `unhandledrejection` event, which is sent when a promise is rejected but there is no handler for the rejection at the time.

Syntax
------

Use the event name in methods like `addEventListener()`, or set an event handler property.


```js
self.addEventListener("rejectionhandled", (event) => {});
self.onrejectionhandled = (event) => {};
```

Event type
----------

A `PromiseRejectionEvent`. Inherits from `Event`.

Event

PromiseRejectionEventEvent properties
----------------

`PromiseRejectionEvent.promise` Read only 

The `Promise` that was rejected.

`PromiseRejectionEvent.reason` Read only 

A value or `Object` indicating why the promise was rejected, as passed to `Promise.reject()`.

Example
-------

You can use the `rejectionhandled` event to log promises that get rejected to the console, along with the reasons why they were rejected:


```js
self.addEventListener("rejectionhandled", (event) => {
  console.log(`Promise rejected; reason: ${event.reason}`);
});
```

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

#### No specification found

No specification data found for `api.WorkerGlobalScope.rejectionhandled_event`.  
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
--------

* Promise rejection events
* `PromiseRejectionEvent`
* `Promise`
* `unhandledrejection`
WorkerGlobalScope: online event
===============================

The **`online`** event of the `WorkerGlobalScope` fires when the device reconnects to the internet.

Syntax
------

Use the event name in methods like `addEventListener()`, or set an event handler property.


```js
addEventListener("online", (event) => {});

ononline = (event) => {};
```

Event type
----------

A generic `Event`.

Example
-------

The following code snippet shows an `onoffline` handler set inside a worker:


```js
self.ononline = () => {
  console.log("Your worker is now online");
};
```


The same snippet, but using `addEventListener()`:


```js
self.addEventListener("online", () => {
  console.log("Your worker is now online");
});
```

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

| Specification |
| --- |
| HTML Standard # handler-workerglobalscope-ononline |

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

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

See also
--------

The `WorkerGlobalScope` interface it belongs to.
WorkerGlobalScope: error event
==============================

The **`error`** event of the `WorkerGlobalScope` interface fires when an error occurs in the worker.

Syntax
------

Use the event name in methods like `addEventListener()`, or set an event handler property.


```js
addEventListener("error", (event) => {});

onerror = (event) => {};
```

Event type
----------

A generic `Event`.

Example
-------

The following code snippet shows an `onerror` handler set inside a worker:


```js
self.onerror = () => {
  console.log("There is an error inside your worker!");
};
```


The same snippet, but using `addEventListener()`:


```js
self.addEventListener("error", () => {
  console.log("There is an error inside your worker!");
});
```

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

| Specification |
| --- |
| HTML Standard # handler-workerglobalscope-onerror |

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

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

See also
--------

The `WorkerGlobalScope` interface it belongs to.
WorkerGlobalScope: languagechange event
=======================================

The **`languagechange`** event is fired at the global scope object when the user's preferred language changes.

This event is not cancelable and does not bubble.

Syntax
------

Use the event name in methods like `addEventListener()`, or set an event handler property.


```js
addEventListener("languagechange", (event) => {});

onlanguagechange = (event) => {};
```

Event type
----------

A generic `Event`.

Examples
--------

You can use the `languagechange` event in an `addEventListener` method:


```js
worker.addEventListener("languagechange", () => {
  console.log("languagechange event detected!");
});
```


Or use the `onlanguagechange` event handler property:


```js
worker.onlanguagechange = (event) => {
  console.log("languagechange event detected!");
};
```

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

| Specification |
| --- |
| HTML Standard # event-languagechange |
| HTML Standard # handler-workerglobalscope-onlanguagechange |

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

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

See also
--------

* `navigator.language`
* `navigator.languages`
* `Navigator`
PerformanceNavigation: type 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 legacy
 **`PerformanceNavigation.type`**
 read-only property returns an `unsigned short` containing a constant
 describing how the navigation to this page was done.


**Warning:** This interface of this property is deprecated in the Navigation Timing Level 2 specification.
 Please use the `PerformanceNavigationTiming` interface instead.


Value
-----

An `unsigned short`.

Possible values are:

| Value | Constant name | Meaning |
| --- | --- | --- |
| `0` | `TYPE_NAVIGATE` | 
 The page was accessed by following a link, a bookmark, a form
 submission, a script, or typing the URL in the address bar.
  |
| `1` | `TYPE_RELOAD` | 
 The page was accessed by clicking the Reload button or via the
 `Location.reload()` method.
  |
| `2` | `TYPE_BACK_FORWARD` | The page was accessed by navigating into the history. |
| `255` | `TYPE_RESERVED` | Any other way. |

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

 This feature is no longer on track to become a standard, as the Navigation Timing specification has marked it as deprecated.
 Use the `PerformanceNavigationTiming` interface instead.

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

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

See also
--------

* The `PerformanceNavigation` interface it belongs to.
PerformanceNavigation: redirectCount 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 legacy
 **`PerformanceNavigation.redirectCount`**
 read-only property returns an `unsigned short` representing the number of
 REDIRECTs done before reaching the page.


**Warning:** This interface of this property is deprecated in the Navigation Timing Level 2 specification.
 Please use the `PerformanceNavigationTiming` interface instead.


Value
-----

An `unsigned short`.

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

 This feature is no longer on track to become a standard, as the Navigation Timing specification has marked it as deprecated.
 Use the `PerformanceNavigationTiming` interface instead.

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

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

See also
--------

* The `PerformanceNavigation` interface it belongs to.