| 79 | /** Registers the handler; returns a disposer. */ |
| 80 | export const installPreloadErrorHandler = (env: PreloadErrorEnvironment): (() => void) => { |
| 81 | const handler = (event: Event) => { |
| 82 | // Always claim the event: Vite rethrows an unclaimed preload error into the |
| 83 | // page as an unhandled rejection, which is the crash report we are here to |
| 84 | // replace with a real recovery path. |
| 85 | event.preventDefault(); |
| 86 | void respondToPreloadError(env, preloadErrorPayload(event)); |
| 87 | }; |
| 88 | env.target.addEventListener(PRELOAD_ERROR_EVENT, handler); |
| 89 | return () => env.target.removeEventListener(PRELOAD_ERROR_EVENT, handler); |
| 90 | }; |