diff --git a/packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts b/packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts index f9379b2a14..11b70fde20 100644 --- a/packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts +++ b/packages/rum-core/src/domain/view/viewMetrics/trackScrollMetrics.ts @@ -102,7 +102,9 @@ export function createScrollValuesObservable( const observerTarget = document.scrollingElement || document.documentElement const resizeObserver = new ResizeObserver(monitor(throttledNotify.throttled)) - resizeObserver.observe(observerTarget) + if (observerTarget) { + resizeObserver.observe(observerTarget) + } const eventListener = addEventListener(configuration, window, DOM_EVENT.SCROLL, throttledNotify.throttled, { passive: true, }) diff --git a/test/e2e/lib/framework/index.ts b/test/e2e/lib/framework/index.ts index 27ce98ee34..35e8a53f9d 100644 --- a/test/e2e/lib/framework/index.ts +++ b/test/e2e/lib/framework/index.ts @@ -5,3 +5,4 @@ export { getTestServers, waitForServersIdle } from './httpServers' export { flushEvents } from './flushEvents' export { waitForRequests } from './waitForRequests' export { LARGE_RESPONSE_MIN_BYTE_SIZE } from './serverApps/mock' +export { RUM_BUNDLE } from './sdkBuilds' diff --git a/test/e2e/scenario/rum/s8sInject.scenario.ts b/test/e2e/scenario/rum/s8sInject.scenario.ts new file mode 100644 index 0000000000..b13c1d76fc --- /dev/null +++ b/test/e2e/scenario/rum/s8sInject.scenario.ts @@ -0,0 +1,41 @@ +import * as fs from 'fs' +import { RUM_BUNDLE } from '../../lib/framework' +import { APPLICATION_ID, CLIENT_TOKEN } from '../../lib/helpers/configuration' + +describe('Inject RUM with Puppeteer', () => { + // S8s tests inject RUM with puppeteer evaluateOnNewDocument + it('should not throw error in chrome', async () => { + const isInjected = await injectRumWithPuppeteer() + expect(isInjected).toBe(true) + }) +}) + +async function injectRumWithPuppeteer() { + const ddRUM = fs.readFileSync(RUM_BUNDLE, 'utf8') + const puppeteerBrowser = await browser.getPuppeteer() + let injected = true + + await browser.call(async () => { + const page = await puppeteerBrowser.newPage() + await page.evaluateOnNewDocument( + ` + if (location.href !== 'about:blank') { + ${ddRUM} + window.DD_RUM._setDebug(true) + window.DD_RUM.init({ + applicationId: ${APPLICATION_ID}, + clientToken: ${CLIENT_TOKEN}, + }) + window.DD_RUM.startView() + } + ` + ) + page.on('console', (msg) => { + if (msg.type() === 'error') { + injected = false + } + }) + await page.goto('https://webdriver.io') + }) + return injected +} diff --git a/test/e2e/wdio.bs.conf.ts b/test/e2e/wdio.bs.conf.ts index 5b48fa81ac..3e369cd75f 100644 --- a/test/e2e/wdio.bs.conf.ts +++ b/test/e2e/wdio.bs.conf.ts @@ -7,7 +7,7 @@ export const config: Options.Testrunner = { ...baseConfig, specFileRetries: 1, - + exclude: [...baseConfig.exclude!, './scenario/rum/s8sInject.scenario.ts'], capabilities: browserConfigurations.map((configuration) => // See https://www.browserstack.com/automate/capabilities?tag=selenium-4 // Make sure to look at the "W3C Protocol" tab