diff --git a/packages/protocol/socket.ts b/packages/protocol/socket.ts index 540701f387d..1c6c94a7bdd 100644 --- a/packages/protocol/socket.ts +++ b/packages/protocol/socket.ts @@ -250,7 +250,9 @@ export async function sendMessage( } const doSend = makeInfallible(message => { - window.performance?.mark(`${message.method}_start`); + if (typeof window !== "undefined") { + window.performance?.mark(`${message.method}_start`); + } const stringified = JSON.stringify(message); gSentBytes += stringified.length; @@ -328,8 +330,10 @@ function socketDataHandler(data: string) { const { method, resolve } = gMessageWaiters.get(msg.id)!; gSessionCallbacks?.onResponse(msg); - window.performance?.mark(`${method}_end`); - window.performance?.measure(method, `${method}_start`, `${method}_end`); + if (typeof window !== "undefined") { + window.performance?.mark(`${method}_end`); + window.performance?.measure(method, `${method}_start`, `${method}_end`); + } gMessageWaiters.delete(msg.id); resolve(msg);