Skip to content

Commit a5996be

Browse files
authored
feat: Remove supportsSendBeacon runtime property (#1224)
1 parent c6a20e1 commit a5996be

File tree

5 files changed

+3
-36
lines changed

5 files changed

+3
-36
lines changed

src/common/constants/__mocks__/runtime.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ export const initialLocation = '' + globalScope?.location
55
export const isiOS = false
66
export const iOSBelow16 = false
77
export const ffVersion = 0
8-
export const supportsSendBeacon = true
98

109
export const originTime = Date.now()

src/common/constants/runtime.js

-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ export const ffVersion = (() => {
7272
return 0
7373
})()
7474

75-
export const supportsSendBeacon = !!globalScope.navigator?.sendBeacon
76-
7775
/**
7876
* Represents the absolute timestamp in milliseconds that the page was loaded
7977
* according to the browser's local clock.

src/common/util/submit-data.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @license Apache-2.0
55
*/
66

7-
import { isBrowserScope, supportsSendBeacon } from '../constants/runtime'
7+
import { isBrowserScope } from '../constants/runtime'
88

99
/**
1010
* @typedef {xhr|beacon} NetworkMethods
@@ -17,7 +17,7 @@ import { isBrowserScope, supportsSendBeacon } from '../constants/runtime'
1717
* a final harvest within the agent.
1818
*/
1919
export function getSubmitMethod ({ isFinalHarvest = false } = {}) {
20-
return isFinalHarvest && isBrowserScope && supportsSendBeacon
20+
return isFinalHarvest && isBrowserScope
2121
// Use sendBeacon for final harvest
2222
? beacon
2323
// If not final harvest, or not browserScope, always use xhr post

tests/unit/common/constants/runtime.test.js

-19
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,3 @@ test.each([
155155
expect(runtime.ffVersion).toEqual(expected)
156156
delete global.window
157157
})
158-
159-
test('should set supportsSendBeacon to false', async () => {
160-
// Ensure we don't have a sendBeacon function
161-
delete global.navigator.sendBeacon
162-
163-
const runtime = await import('../../../../src/common/constants/runtime')
164-
165-
expect(runtime.supportsSendBeacon).toEqual(false)
166-
})
167-
168-
test('should set supportsSendBeacon to true', async () => {
169-
global.navigator.sendBeacon = jest.fn()
170-
global.window = { navigator: global.navigator, document: true }
171-
172-
const runtime = await import('../../../../src/common/constants/runtime')
173-
174-
expect(runtime.supportsSendBeacon).toEqual(true)
175-
delete global.window
176-
})

tests/unit/common/util/submit-data.test.js

+1-12
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,12 @@ afterEach(() => {
1919
describe('getSubmitMethod', () => {
2020
test('should use xhr for final harvest when isBrowserScope is false', () => {
2121
jest.replaceProperty(runtimeModule, 'isBrowserScope', false)
22-
jest.replaceProperty(runtimeModule, 'supportsSendBeacon', true)
2322

2423
expect(submitData.getSubmitMethod({ isFinalHarvest: true })).toEqual(submitData.xhr)
2524
})
2625

27-
test('should use xhr for final harvest when supportsSendBeacon is false', () => {
26+
test('should use beacon for final harvest when isBrowserScope is true', () => {
2827
jest.replaceProperty(runtimeModule, 'isBrowserScope', true)
29-
jest.replaceProperty(runtimeModule, 'supportsSendBeacon', false)
30-
31-
expect(submitData.getSubmitMethod({ isFinalHarvest: true })).toEqual(submitData.xhr)
32-
})
33-
34-
test('should use beacon for final harvest when isBrowserScope and supportsSendBeacon is true', () => {
35-
jest.replaceProperty(runtimeModule, 'isBrowserScope', true)
36-
jest.replaceProperty(runtimeModule, 'supportsSendBeacon', true)
3728

3829
expect(submitData.getSubmitMethod({ isFinalHarvest: true })).toEqual(submitData.beacon)
3930
})
@@ -42,14 +33,12 @@ describe('getSubmitMethod', () => {
4233
null, undefined, false
4334
])('should use xhr when final harvest is %s', (isFinalHarvest) => {
4435
jest.replaceProperty(runtimeModule, 'isBrowserScope', true)
45-
jest.replaceProperty(runtimeModule, 'supportsSendBeacon', true)
4636

4737
expect(submitData.getSubmitMethod({ isFinalHarvest })).toEqual(submitData.xhr)
4838
})
4939

5040
test('should use xhr when opts is undefined', () => {
5141
jest.replaceProperty(runtimeModule, 'isBrowserScope', true)
52-
jest.replaceProperty(runtimeModule, 'supportsSendBeacon', true)
5342

5443
expect(submitData.getSubmitMethod()).toEqual(submitData.xhr)
5544
})

0 commit comments

Comments
 (0)