Skip to content

Commit

Permalink
we need to guard these window accesses to
Browse files Browse the repository at this point in the history
  • Loading branch information
toshok committed Oct 30, 2024
1 parent fd67d4c commit 20ba069
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 20ba069

Please sign in to comment.