Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ import { BROWSER_ATTRIBUTES, UserAgentData } from './types';
*/
class BrowserDetector implements ResourceDetector {
detect(config?: ResourceDetectionConfig): DetectedResource {
const isBrowser = typeof navigator !== 'undefined';
const isBrowser =
typeof navigator !== 'undefined' &&
// @ts-ignore
globalThis.process?.versions?.node === undefined &&
// @ts-ignore
globalThis.Bun?.version === undefined;

if (!isBrowser) {
return emptyResource();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,12 @@ describeBrowser('browserDetector()', () => {
assertEmptyResource(resource);
});
});

describe('browserDetector() in Node.js', () => {
it('should return empty resource in Node.js environment even if navigator is present', () => {
// We don't need to stub navigator because I am are on Node 24
const resource = browserDetector.detect();

assertEmptyResource(resource);
});
});