Skip to content

Commit 7b2c2ae

Browse files
authored
fix: move node check to init (#1088)
1 parent d784ea6 commit 7b2c2ae

File tree

3 files changed

+9
-25
lines changed

3 files changed

+9
-25
lines changed

packages/web/src/check-browser.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/web/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*
1717
*/
1818

19-
import './check-browser'
2019
import './polyfill-safari10'
2120
import { registerInstrumentations } from '@opentelemetry/instrumentation'
2221
import {
@@ -288,6 +287,13 @@ export const SplunkRum: SplunkOtelWebType = {
288287

289288
init: function (options) {
290289
userTrackingMode = options.user?.trackingMode ?? 'noTracking'
290+
291+
if (typeof window !== 'object') {
292+
throw Error(
293+
'SplunkRum Error: This library is intended to run in a browser environment. Please ensure the code is evaluated within a browser context.',
294+
)
295+
}
296+
291297
// "env" based config still a bad idea for web
292298
if (!('OTEL_TRACES_EXPORTER' in _globalThis)) {
293299
_globalThis.OTEL_TRACES_EXPORTER = 'none'

packages/web/src/storage/cookie-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { isIframe } from '../utils'
2020
import { throttle } from '../utils/throttle'
2121
import { Store } from './store'
2222

23-
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
23+
const isSafari = () => /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
2424

2525
export class CookieStore<T> implements Store<T> {
2626
private cachedValue: T | undefined
@@ -92,7 +92,7 @@ export class CookieStore<T> implements Store<T> {
9292
if (isIframe()) {
9393
// Safari does not set cookie when the SameSite attribute is set to None and Secure is set to true in an iframe
9494
// It fails also in our unit tests since they are running in iframe and on localhost.
95-
if (['localhost', '127.0.0.1'].includes(window.location.hostname) && isSafari) {
95+
if (['localhost', '127.0.0.1'].includes(window.location.hostname) && isSafari()) {
9696
rawCookie += ';SameSite=None'
9797
} else {
9898
rawCookie += ';SameSite=None; Secure'

0 commit comments

Comments
 (0)