Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [RUM-6411] RUM should not crash with puppeteer injection #3153

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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 @@ -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 instanceof Element) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion:

Suggested change
if (observerTarget instanceof Element) {
if (observerTarget) {

resizeObserver.observe(observerTarget)
}
const eventListener = addEventListener(configuration, window, DOM_EVENT.SCROLL, throttledNotify.throttled, {
passive: true,
})
Expand Down
32 changes: 32 additions & 0 deletions test/e2e/lib/framework/createTest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from 'fs'
import type { LogsInitConfiguration } from '@datadog/browser-logs'
import type { RumInitConfiguration } from '@datadog/browser-rum-core'
import { DefaultPrivacyLevel } from '@datadog/browser-rum'
Expand All @@ -14,6 +15,7 @@ import type { SetupFactory, SetupOptions } from './pageSetups'
import { DEFAULT_SETUPS, npmSetup } from './pageSetups'
import { createIntakeServerApp } from './serverApps/intake'
import { createMockServerApp } from './serverApps/mock'
import { RUM_BUNDLE } from './sdkBuilds'

const DEFAULT_RUM_CONFIGURATION = {
applicationId: APPLICATION_ID,
Expand Down Expand Up @@ -228,3 +230,33 @@ async function tearDownTest({ intakeRegistry }: TestContext) {
})
await deleteAllCookies()
}

export async function injectRumWithPuppeteer() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 suggestion: ‏Move this function out of this module as it has little to do with the createTest helper. Since it is only one test case, you could even inline the code inside of the test

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
}
2 changes: 1 addition & 1 deletion test/e2e/lib/framework/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { createTest } from './createTest'
export { createTest, injectRumWithPuppeteer } from './createTest'
export { bundleSetup, html } from './pageSetups'
export { IntakeRegistry } from './intakeRegistry'
export { getTestServers, waitForServersIdle } from './httpServers'
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/scenario/rum/s8sInject.scenario.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { injectRumWithPuppeteer } from '../../lib/framework'
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)
})
})
2 changes: 1 addition & 1 deletion test/e2e/wdio.bs.conf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down