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 all 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) {
resizeObserver.observe(observerTarget)
}
const eventListener = addEventListener(configuration, window, DOM_EVENT.SCROLL, throttledNotify.throttled, {
passive: true,
})
Expand Down
1 change: 1 addition & 0 deletions test/e2e/lib/framework/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
41 changes: 41 additions & 0 deletions test/e2e/scenario/rum/s8sInject.scenario.ts
Original file line number Diff line number Diff line change
@@ -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
}
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