Skip to content

Commit

Permalink
add guards to a couple more window accesses in socket.ts (#10620)
Browse files Browse the repository at this point in the history
trying to use this package from outside a browser.  some window references are guarded, but these weren't.
  • Loading branch information
toshok authored Oct 30, 2024
1 parent fd67d4c commit ec45e5a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/protocol/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ export async function sendMessage<M extends CommandMethods>(
}

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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ec45e5a

Please sign in to comment.