# Service Worker WebIDL
Sample output from `get_webidl` tool with shortname `service-workers`.
## Main Interfaces
### ServiceWorker
```webidl
[SecureContext, Exposed=(Window,Worker)]
interface ServiceWorker : EventTarget {
readonly attribute USVString scriptURL;
readonly attribute ServiceWorkerState state;
undefined postMessage(any message, sequence<object> transfer);
undefined postMessage(any message, optional StructuredSerializeOptions options = {});
attribute EventHandler onstatechange;
};
enum ServiceWorkerState {
"parsed",
"installing",
"installed",
"activating",
"activated",
"redundant"
};
```
### ServiceWorkerRegistration
```webidl
[SecureContext, Exposed=(Window,Worker)]
interface ServiceWorkerRegistration : EventTarget {
readonly attribute ServiceWorker? installing;
readonly attribute ServiceWorker? waiting;
readonly attribute ServiceWorker? active;
[SameObject] readonly attribute NavigationPreloadManager navigationPreload;
readonly attribute USVString scope;
readonly attribute ServiceWorkerUpdateViaCache updateViaCache;
[NewObject] Promise<ServiceWorkerRegistration> update();
[NewObject] Promise<boolean> unregister();
attribute EventHandler onupdatefound;
};
```
### ServiceWorkerContainer
```webidl
[SecureContext, Exposed=(Window,Worker)]
interface ServiceWorkerContainer : EventTarget {
readonly attribute ServiceWorker? controller;
readonly attribute Promise<ServiceWorkerRegistration> ready;
[NewObject] Promise<ServiceWorkerRegistration> register(
(TrustedScriptURL or USVString) scriptURL,
optional RegistrationOptions options = {}
);
[NewObject] Promise<(ServiceWorkerRegistration or undefined)> getRegistration(
optional USVString clientURL = ""
);
[NewObject] Promise<FrozenArray<ServiceWorkerRegistration>> getRegistrations();
undefined startMessages();
attribute EventHandler oncontrollerchange;
attribute EventHandler onmessage;
attribute EventHandler onmessageerror;
};
```
## Cache API
### Cache
```webidl
[SecureContext, Exposed=(Window,Worker)]
interface Cache {
[NewObject] Promise<(Response or undefined)> match(
RequestInfo request, optional CacheQueryOptions options = {}
);
[NewObject] Promise<FrozenArray<Response>> matchAll(
optional RequestInfo request, optional CacheQueryOptions options = {}
);
[NewObject] Promise<undefined> add(RequestInfo request);
[NewObject] Promise<undefined> addAll(sequence<RequestInfo> requests);
[NewObject] Promise<undefined> put(RequestInfo request, Response response);
[NewObject] Promise<boolean> delete(
RequestInfo request, optional CacheQueryOptions options = {}
);
[NewObject] Promise<FrozenArray<Request>> keys(
optional RequestInfo request, optional CacheQueryOptions options = {}
);
};
```
### CacheStorage
```webidl
[SecureContext, Exposed=(Window,Worker)]
interface CacheStorage {
[NewObject] Promise<(Response or undefined)> match(
RequestInfo request, optional MultiCacheQueryOptions options = {}
);
[NewObject] Promise<boolean> has(DOMString cacheName);
[NewObject] Promise<Cache> open(DOMString cacheName);
[NewObject] Promise<boolean> delete(DOMString cacheName);
[NewObject] Promise<sequence<DOMString>> keys();
};
```
## Events
### FetchEvent
```webidl
[Exposed=ServiceWorker]
interface FetchEvent : ExtendableEvent {
constructor(DOMString type, FetchEventInit eventInitDict);
[SameObject] readonly attribute Request request;
readonly attribute Promise<any> preloadResponse;
readonly attribute DOMString clientId;
readonly attribute DOMString resultingClientId;
readonly attribute DOMString replacesClientId;
readonly attribute Promise<undefined> handled;
undefined respondWith(Promise<Response> r);
};
```
### ExtendableEvent
```webidl
[Exposed=ServiceWorker]
interface ExtendableEvent : Event {
constructor(DOMString type, optional ExtendableEventInit eventInitDict = {});
undefined waitUntil(Promise<any> f);
};
```
---
*Generated by W3C MCP Server `get_webidl` tool*