mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 20:17:09 +00:00
fix(web-runtime): guard global error listeners for non-browser hosts
The module registered window error/unhandledrejection listeners at top level, which threw under Node (the spec-api test runner) where globalThis.addEventListener is absent. Register only when the API exists; the real browser run is unaffected.
This commit is contained in:
1 parent
95d64d6452
commit
c41e4d0195
1 file changed
+6
-4
@@ -339,12 +339,14 @@ function recordException(error: unknown): void {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
globalThis.addEventListener("error", (event: ErrorEvent) => {
|
if (typeof globalThis.addEventListener === "function") {
|
||||||
|
globalThis.addEventListener("error", (event: ErrorEvent) => {
|
||||||
recordException(event.error ?? event.message);
|
recordException(event.error ?? event.message);
|
||||||
});
|
});
|
||||||
globalThis.addEventListener("unhandledrejection", (event: PromiseRejectionEvent) => {
|
globalThis.addEventListener("unhandledrejection", (event: PromiseRejectionEvent) => {
|
||||||
recordException(event.reason);
|
recordException(event.reason);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function buildState(): unknown {
|
function buildState(): unknown {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in new issue
Block a user