service-workers.idl (8761B)
1 // GENERATED CONTENT - DO NOT EDIT 2 // Content was automatically extracted by Reffy into webref 3 // (https://github.com/w3c/webref) 4 // Source: Service Workers Nightly (https://w3c.github.io/ServiceWorker/) 5 6 [SecureContext, Exposed=(Window,Worker)] 7 interface ServiceWorker : EventTarget { 8 readonly attribute USVString scriptURL; 9 readonly attribute ServiceWorkerState state; 10 undefined postMessage(any message, sequence<object> transfer); 11 undefined postMessage(any message, optional StructuredSerializeOptions options = {}); 12 13 // event 14 attribute EventHandler onstatechange; 15 }; 16 ServiceWorker includes AbstractWorker; 17 18 enum ServiceWorkerState { 19 "parsed", 20 "installing", 21 "installed", 22 "activating", 23 "activated", 24 "redundant" 25 }; 26 27 [SecureContext, Exposed=(Window,Worker)] 28 interface ServiceWorkerRegistration : EventTarget { 29 readonly attribute ServiceWorker? installing; 30 readonly attribute ServiceWorker? waiting; 31 readonly attribute ServiceWorker? active; 32 [SameObject] readonly attribute NavigationPreloadManager navigationPreload; 33 34 readonly attribute USVString scope; 35 readonly attribute ServiceWorkerUpdateViaCache updateViaCache; 36 37 [NewObject] Promise<ServiceWorkerRegistration> update(); 38 [NewObject] Promise<boolean> unregister(); 39 40 // event 41 attribute EventHandler onupdatefound; 42 }; 43 44 enum ServiceWorkerUpdateViaCache { 45 "imports", 46 "all", 47 "none" 48 }; 49 50 partial interface Navigator { 51 [SecureContext, SameObject] readonly attribute ServiceWorkerContainer serviceWorker; 52 }; 53 54 partial interface WorkerNavigator { 55 [SecureContext, SameObject] readonly attribute ServiceWorkerContainer serviceWorker; 56 }; 57 58 [SecureContext, Exposed=(Window,Worker)] 59 interface ServiceWorkerContainer : EventTarget { 60 readonly attribute ServiceWorker? controller; 61 readonly attribute Promise<ServiceWorkerRegistration> ready; 62 63 [NewObject] Promise<ServiceWorkerRegistration> register((TrustedScriptURL or USVString) scriptURL, optional RegistrationOptions options = {}); 64 65 [NewObject] Promise<(ServiceWorkerRegistration or undefined)> getRegistration(optional USVString clientURL = ""); 66 [NewObject] Promise<FrozenArray<ServiceWorkerRegistration>> getRegistrations(); 67 68 undefined startMessages(); 69 70 // events 71 attribute EventHandler oncontrollerchange; 72 attribute EventHandler onmessage; // event.source of message events is ServiceWorker object 73 attribute EventHandler onmessageerror; 74 }; 75 76 dictionary RegistrationOptions { 77 USVString scope; 78 WorkerType type = "classic"; 79 ServiceWorkerUpdateViaCache updateViaCache = "imports"; 80 }; 81 82 [SecureContext, Exposed=(Window,Worker)] 83 interface NavigationPreloadManager { 84 Promise<undefined> enable(); 85 Promise<undefined> disable(); 86 Promise<undefined> setHeaderValue(ByteString value); 87 Promise<NavigationPreloadState> getState(); 88 }; 89 90 dictionary NavigationPreloadState { 91 boolean enabled = false; 92 ByteString headerValue; 93 }; 94 95 [Global=(Worker,ServiceWorker), Exposed=ServiceWorker, SecureContext] 96 interface ServiceWorkerGlobalScope : WorkerGlobalScope { 97 [SameObject] readonly attribute Clients clients; 98 [SameObject] readonly attribute ServiceWorkerRegistration registration; 99 [SameObject] readonly attribute ServiceWorker serviceWorker; 100 101 [NewObject] Promise<undefined> skipWaiting(); 102 103 attribute EventHandler oninstall; 104 attribute EventHandler onactivate; 105 attribute EventHandler onfetch; 106 107 attribute EventHandler onmessage; 108 attribute EventHandler onmessageerror; 109 }; 110 111 [Exposed=ServiceWorker] 112 interface Client { 113 readonly attribute USVString url; 114 readonly attribute FrameType frameType; 115 readonly attribute DOMString id; 116 readonly attribute ClientType type; 117 undefined postMessage(any message, sequence<object> transfer); 118 undefined postMessage(any message, optional StructuredSerializeOptions options = {}); 119 }; 120 121 [Exposed=ServiceWorker] 122 interface WindowClient : Client { 123 readonly attribute DocumentVisibilityState visibilityState; 124 readonly attribute boolean focused; 125 [SameObject] readonly attribute FrozenArray<USVString> ancestorOrigins; 126 [NewObject] Promise<WindowClient> focus(); 127 [NewObject] Promise<WindowClient?> navigate(USVString url); 128 }; 129 130 enum FrameType { 131 "auxiliary", 132 "top-level", 133 "nested", 134 "none" 135 }; 136 137 [Exposed=ServiceWorker] 138 interface Clients { 139 // The objects returned will be new instances every time 140 [NewObject] Promise<(Client or undefined)> get(DOMString id); 141 [NewObject] Promise<FrozenArray<Client>> matchAll(optional ClientQueryOptions options = {}); 142 [NewObject] Promise<WindowClient?> openWindow(USVString url); 143 [NewObject] Promise<undefined> claim(); 144 }; 145 146 dictionary ClientQueryOptions { 147 boolean includeUncontrolled = false; 148 ClientType type = "window"; 149 }; 150 151 enum ClientType { 152 "window", 153 "worker", 154 "sharedworker", 155 "all" 156 }; 157 158 [Exposed=ServiceWorker] 159 interface ExtendableEvent : Event { 160 constructor(DOMString type, optional ExtendableEventInit eventInitDict = {}); 161 undefined waitUntil(Promise<any> f); 162 }; 163 164 dictionary ExtendableEventInit : EventInit { 165 // Defined for the forward compatibility across the derived events 166 }; 167 168 [Exposed=ServiceWorker] 169 interface InstallEvent : ExtendableEvent { 170 constructor(DOMString type, optional ExtendableEventInit eventInitDict = {}); 171 Promise<undefined> addRoutes((RouterRule or sequence<RouterRule>) rules); 172 }; 173 174 dictionary RouterRule { 175 required RouterCondition condition; 176 required RouterSource source; 177 }; 178 179 dictionary RouterCondition { 180 URLPatternCompatible urlPattern; 181 ByteString requestMethod; 182 RequestMode requestMode; 183 RequestDestination requestDestination; 184 RunningStatus runningStatus; 185 186 sequence<RouterCondition> _or; 187 RouterCondition not; 188 }; 189 190 typedef (RouterSourceDict or RouterSourceEnum) RouterSource; 191 192 dictionary RouterSourceDict { 193 DOMString cacheName; 194 }; 195 196 enum RunningStatus { "running", "not-running" }; 197 enum RouterSourceEnum { 198 "cache", 199 "fetch-event", 200 "network", 201 "race-network-and-fetch-handler" 202 }; 203 204 [Exposed=ServiceWorker] 205 interface FetchEvent : ExtendableEvent { 206 constructor(DOMString type, FetchEventInit eventInitDict); 207 [SameObject] readonly attribute Request request; 208 readonly attribute Promise<any> preloadResponse; 209 readonly attribute DOMString clientId; 210 readonly attribute DOMString resultingClientId; 211 readonly attribute DOMString replacesClientId; 212 readonly attribute Promise<undefined> handled; 213 214 undefined respondWith(Promise<Response> r); 215 }; 216 217 dictionary FetchEventInit : ExtendableEventInit { 218 required Request request; 219 Promise<any> preloadResponse; 220 DOMString clientId = ""; 221 DOMString resultingClientId = ""; 222 DOMString replacesClientId = ""; 223 Promise<undefined> handled; 224 }; 225 226 [Exposed=ServiceWorker] 227 interface ExtendableMessageEvent : ExtendableEvent { 228 constructor(DOMString type, optional ExtendableMessageEventInit eventInitDict = {}); 229 readonly attribute any data; 230 readonly attribute USVString origin; 231 readonly attribute DOMString lastEventId; 232 [SameObject] readonly attribute (Client or ServiceWorker or MessagePort)? source; 233 readonly attribute FrozenArray<MessagePort> ports; 234 }; 235 236 dictionary ExtendableMessageEventInit : ExtendableEventInit { 237 any data = null; 238 USVString origin = ""; 239 DOMString lastEventId = ""; 240 (Client or ServiceWorker or MessagePort)? source = null; 241 sequence<MessagePort> ports = []; 242 }; 243 244 partial interface mixin WindowOrWorkerGlobalScope { 245 [SecureContext, SameObject] readonly attribute CacheStorage caches; 246 }; 247 248 [SecureContext, Exposed=(Window,Worker)] 249 interface Cache { 250 [NewObject] Promise<(Response or undefined)> match(RequestInfo request, optional CacheQueryOptions options = {}); 251 [NewObject] Promise<FrozenArray<Response>> matchAll(optional RequestInfo request, optional CacheQueryOptions options = {}); 252 [NewObject] Promise<undefined> add(RequestInfo request); 253 [NewObject] Promise<undefined> addAll(sequence<RequestInfo> requests); 254 [NewObject] Promise<undefined> put(RequestInfo request, Response response); 255 [NewObject] Promise<boolean> delete(RequestInfo request, optional CacheQueryOptions options = {}); 256 [NewObject] Promise<FrozenArray<Request>> keys(optional RequestInfo request, optional CacheQueryOptions options = {}); 257 }; 258 259 dictionary CacheQueryOptions { 260 boolean ignoreSearch = false; 261 boolean ignoreMethod = false; 262 boolean ignoreVary = false; 263 }; 264 265 [SecureContext, Exposed=(Window,Worker)] 266 interface CacheStorage { 267 [NewObject] Promise<(Response or undefined)> match(RequestInfo request, optional MultiCacheQueryOptions options = {}); 268 [NewObject] Promise<boolean> has(DOMString cacheName); 269 [NewObject] Promise<Cache> open(DOMString cacheName); 270 [NewObject] Promise<boolean> delete(DOMString cacheName); 271 [NewObject] Promise<sequence<DOMString>> keys(); 272 }; 273 274 dictionary MultiCacheQueryOptions : CacheQueryOptions { 275 DOMString cacheName; 276 };