* Registers a service worker for this instances script URL and register * options and tracks the time registration was complete. * * @private
()
| 354 | * @private |
| 355 | */ |
| 356 | private async _registerScript() { |
| 357 | try { |
| 358 | // this._scriptURL may be a TrustedScriptURL, but there's no support for |
| 359 | // passing that to register() in lib.dom right now. |
| 360 | // https://github.com/GoogleChrome/workbox/issues/2855 |
| 361 | const reg = await navigator.serviceWorker.register( |
| 362 | this._scriptURL as string, |
| 363 | this._registerOptions, |
| 364 | ); |
| 365 | |
| 366 | // Keep track of when registration happened, so it can be used in the |
| 367 | // `this._onUpdateFound` heuristic. Also use the presence of this |
| 368 | // property as a way to see if `.register()` has been called. |
| 369 | this._registrationTime = performance.now(); |
| 370 | |
| 371 | return reg; |
| 372 | } catch (error) { |
| 373 | if (process.env.NODE_ENV !== 'production') { |
| 374 | logger.error(error); |
| 375 | } |
| 376 | // Re-throw the error. |
| 377 | throw error; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * @private |