From 8b19a1609337334d5776472373c77d42a18172e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt?= Date: Mon, 6 Dec 2021 17:37:22 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[RUMF-1082]=20enable=20record-at-do?= =?UTF-8?q?m-loaded=20(#1182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/rum/src/boot/recorderApi.spec.ts | 76 ++--------------------- packages/rum/src/boot/recorderApi.ts | 10 +-- 2 files changed, 7 insertions(+), 79 deletions(-) diff --git a/packages/rum/src/boot/recorderApi.spec.ts b/packages/rum/src/boot/recorderApi.spec.ts index 3d3529b8ff..c50a212d53 100644 --- a/packages/rum/src/boot/recorderApi.spec.ts +++ b/packages/rum/src/boot/recorderApi.spec.ts @@ -57,7 +57,6 @@ describe('makeRecorderApi', () => { afterEach(() => { setupBuilder.cleanup() - resetExperimentalFeatures() }) describe('boot', () => { @@ -68,17 +67,7 @@ describe('makeRecorderApi', () => { expect(startRecordingSpy).not.toHaveBeenCalled() }) - it('without "record-at-dom-loaded", does not start recording after the page "load"', () => { - setupBuilder.build() - const { triggerOnLoad } = mockDocumentReadyState() - rumInit(DEFAULT_INIT_CONFIGURATION) - expect(startRecordingSpy).not.toHaveBeenCalled() - triggerOnLoad() - expect(startRecordingSpy).not.toHaveBeenCalled() - }) - - it('with "record-at-dom-loaded", does not start recording after the DOM is loaded', () => { - updateExperimentalFeatures(['record-at-dom-loaded']) + it('does not start recording after the DOM is loaded', () => { setupBuilder.build() const { triggerOnDomLoaded } = mockDocumentReadyState() rumInit(DEFAULT_INIT_CONFIGURATION) @@ -105,20 +94,7 @@ describe('makeRecorderApi', () => { expect(startRecordingSpy).toHaveBeenCalled() }) - it('without "record-at-dom-loaded", does not start recording multiple times if restarted before onload', () => { - setupBuilder.build() - const { triggerOnLoad } = mockDocumentReadyState() - rumInit(DEFAULT_INIT_CONFIGURATION) - recorderApi.start() - recorderApi.stop() - recorderApi.start() - triggerOnLoad() - expect(startRecordingSpy).toHaveBeenCalledTimes(1) - }) - - // eslint-disable-next-line max-len - it('with "record-at-dom-loaded", does not start recording multiple times if restarted before the DOM is loaded', () => { - updateExperimentalFeatures(['record-at-dom-loaded']) + it('does not start recording multiple times if restarted before the DOM is loaded', () => { setupBuilder.build() const { triggerOnDomLoaded } = mockDocumentReadyState() rumInit(DEFAULT_INIT_CONFIGURATION) @@ -203,18 +179,7 @@ describe('makeRecorderApi', () => { expect(startRecordingSpy).not.toHaveBeenCalled() }) - it('without "record-at-dom-loaded", prevents recording to start at page "load"', () => { - setupBuilder.build() - const { triggerOnLoad } = mockDocumentReadyState() - rumInit(DEFAULT_INIT_CONFIGURATION) - recorderApi.start() - recorderApi.stop() - triggerOnLoad() - expect(startRecordingSpy).not.toHaveBeenCalled() - }) - - it('with "record-at-dom-loaded", prevents recording to start when the DOM is loaded', () => { - updateExperimentalFeatures(['record-at-dom-loaded']) + it('prevents recording to start when the DOM is loaded', () => { setupBuilder.build() const { triggerOnDomLoaded } = mockDocumentReadyState() rumInit(DEFAULT_INIT_CONFIGURATION) @@ -304,22 +269,7 @@ describe('makeRecorderApi', () => { expect(startRecordingSpy).toHaveBeenCalledTimes(1) }) - // eslint-disable-next-line max-len - it('without "record-at-dom-loaded", prevents session recording to start if the session is renewed before onload', () => { - setupBuilder.build() - const { triggerOnLoad } = mockDocumentReadyState() - rumInit(DEFAULT_INIT_CONFIGURATION) - recorderApi.start() - session.setLitePlan() - lifeCycle.notify(LifeCycleEventType.SESSION_EXPIRED) - lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED) - triggerOnLoad() - expect(startRecordingSpy).not.toHaveBeenCalled() - }) - - // eslint-disable-next-line max-len - it('with "record-at-dom-loaded", prevents session recording to start if the session is renewed before the DOM is loaded', () => { - updateExperimentalFeatures(['record-at-dom-loaded']) + it('prevents session recording to start if the session is renewed before the DOM is loaded', () => { setupBuilder.build() const { triggerOnDomLoaded } = mockDocumentReadyState() rumInit(DEFAULT_INIT_CONFIGURATION) @@ -440,19 +390,7 @@ describe('makeRecorderApi', () => { expect(recorderApi.isRecording()).toBeFalse() }) - it('without "record-at-dom-loaded", is false before page "load"', () => { - setupBuilder.build() - const { triggerOnLoad } = mockDocumentReadyState() - rumInit(DEFAULT_INIT_CONFIGURATION) - expect(recorderApi.isRecording()).toBeFalse() - recorderApi.start() - expect(recorderApi.isRecording()).toBeFalse() - triggerOnLoad() - expect(recorderApi.isRecording()).toBeTrue() - }) - - it('with "record-at-dom-loaded", is false before the DOM is loaded', () => { - updateExperimentalFeatures(['record-at-dom-loaded']) + it('is false before the DOM is loaded', () => { setupBuilder.build() const { triggerOnDomLoaded } = mockDocumentReadyState() rumInit(DEFAULT_INIT_CONFIGURATION) @@ -473,9 +411,5 @@ function mockDocumentReadyState() { readyState = 'interactive' window.dispatchEvent(createNewEvent('DOMContentLoaded')) }, - triggerOnLoad: () => { - readyState = 'complete' - window.dispatchEvent(createNewEvent('load')) - }, } } diff --git a/packages/rum/src/boot/recorderApi.ts b/packages/rum/src/boot/recorderApi.ts index 6768e5d1b9..5251db2bbf 100644 --- a/packages/rum/src/boot/recorderApi.ts +++ b/packages/rum/src/boot/recorderApi.ts @@ -1,10 +1,4 @@ -import { - Configuration, - canUseEventBridge, - noop, - runOnReadyState, - isExperimentalFeatureEnabled, -} from '@datadog/browser-core' +import { Configuration, canUseEventBridge, noop, runOnReadyState } from '@datadog/browser-core' import { LifeCycleEventType, RumInitConfiguration, @@ -107,7 +101,7 @@ export function makeRecorderApi( state = { status: RecorderStatus.Starting } - runOnReadyState(isExperimentalFeatureEnabled('record-at-dom-loaded') ? 'interactive' : 'complete', () => { + runOnReadyState('interactive', () => { if (state.status !== RecorderStatus.Starting) { return }