Commit 4818678
authored
fix(js-client-sdk): better
This PR addresses
SDK-2235
SDK-2236
changes:
- changing `isDocument` to `isWindow` because that is more semanitcally
correct (we are using `window` in the conditional block)
- changing bare check to type check (`crypto` -> `typeof crypto !==
'undefined'`) so that the code doesn't throw due to `crypto` not
existing (this should never happen unless running on some bad obscure
browser)
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Low Risk**
> Low risk: small guard-condition fixes around `window` and `crypto`
presence to avoid runtime errors in non-browser/limited environments.
Behavior changes only when these globals are missing, where the previous
code could throw or incorrectly skip listener registration.
>
> **Overview**
> Fixes environment detection in the browser SDK by gating
`addWindowEventListener` on `isWindow()` (matching the actual `window`
usage) and updating the no-op comment accordingly.
>
> Hardens UUID v4 generation in both the SDK and browser-telemetry
packages by replacing the unsafe `crypto` truthiness check with `typeof
crypto !== 'undefined'` before calling `crypto.getRandomValues`,
preventing ReferenceErrors when `crypto` is absent.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
3cee041. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->undefined handling (#1303)1 parent f4bd636 commit 4818678
3 files changed
Lines changed: 4 additions & 4 deletions
File tree
- packages
- sdk/browser/src
- platform
- telemetry/browser-telemetry/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| |||
0 commit comments