Skip to content

Commit 20c18ad

Browse files
Adding guarding if for missing document/body/documentElement in initializeResizeObserver
1 parent bea8358 commit 20c18ad

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

libraries/browser-tracker-core/src/helpers/browser_props.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ function initializeResizeObserver() {
2222
if (resizeObserverInitialized) {
2323
return;
2424
}
25+
if(!document || !document.body || !document.documentElement) {
26+
return;
27+
}
2528
resizeObserverInitialized = true;
2629

2730
const resizeObserver = new ResizeObserver((entries) => {

libraries/browser-tracker-core/test/browser_props.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { floorDimensionFields } from '../src/helpers/browser_props';
1+
import { floorDimensionFields, getBrowserProperties } from '../src/helpers/browser_props';
22

33
describe('Browser props', () => {
44
it('floorDimensionFields correctly floors dimension type values', () => {
@@ -10,4 +10,18 @@ describe('Browser props', () => {
1010
const testFractionalDimensions = '100.2x100.1';
1111
expect(floorDimensionFields(testFractionalDimensions)).toEqual('100x100');
1212
});
13+
14+
describe('#getBrowserProperties', () => {
15+
describe('with undefined document', () => {
16+
beforeAll(() => {
17+
// @ts-expect-error
18+
document = undefined;
19+
});
20+
21+
it('does not invoke the resize observer if the document is null', () => {
22+
const browserProperties = getBrowserProperties();
23+
expect(browserProperties).not.toEqual(null);
24+
});
25+
});
26+
});
1327
});

0 commit comments

Comments
 (0)