-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(replay): Consider window.open
for slow clicks
#8308
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/browser-integration-tests/suites/replay/slowClick/windowOpen/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getCustomRecordingEvents, shouldSkipReplayTest, waitForReplayRequest } from '../../../../utils/replayHelpers'; | ||
|
||
sentryTest('window.open() is considered for slow click', async ({ getLocalTestUrl, page, browser }) => { | ||
if (shouldSkipReplayTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const reqPromise0 = waitForReplayRequest(page, 0); | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
await reqPromise0; | ||
|
||
const reqPromise1 = waitForReplayRequest(page, (event, res) => { | ||
const { breadcrumbs } = getCustomRecordingEvents(res); | ||
|
||
return breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.click'); | ||
}); | ||
|
||
// Ensure window.open() still works as expected | ||
const context = browser.contexts()[0]; | ||
const waitForNewPage = context.waitForEvent('page'); | ||
|
||
await page.click('#windowOpenButton'); | ||
|
||
const { breadcrumbs } = getCustomRecordingEvents(await reqPromise1); | ||
|
||
// Filter out potential blur breadcrumb, as otherwise this can be flaky | ||
const filteredBreadcrumb = breadcrumbs.filter(breadcrumb => breadcrumb.category !== 'ui.blur'); | ||
|
||
expect(filteredBreadcrumb).toEqual([ | ||
{ | ||
category: 'ui.click', | ||
data: { | ||
node: { | ||
attributes: { | ||
id: 'windowOpenButton', | ||
}, | ||
id: expect.any(Number), | ||
tagName: 'button', | ||
textContent: '****** ****', | ||
}, | ||
nodeId: expect.any(Number), | ||
}, | ||
message: 'body > button#windowOpenButton', | ||
timestamp: expect.any(Number), | ||
type: 'default', | ||
}, | ||
]); | ||
|
||
await waitForNewPage; | ||
|
||
const pages = context.pages(); | ||
|
||
expect(pages.length).toBe(2); | ||
expect(pages[1].url()).toBe('https://example.com/'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { fill } from '@sentry/utils'; | ||
|
||
import { WINDOW } from '../../constants'; | ||
|
||
type WindowOpenHandler = () => void; | ||
|
||
let handlers: undefined | WindowOpenHandler[]; | ||
|
||
/** | ||
* Register a handler to be called when `window.open()` is called. | ||
* Returns a cleanup function. | ||
*/ | ||
export function onWindowOpen(cb: WindowOpenHandler): () => void { | ||
// Ensure to only register this once | ||
if (!handlers) { | ||
handlers = []; | ||
monkeyPatchWindowOpen(); | ||
} | ||
|
||
handlers.push(cb); | ||
|
||
return () => { | ||
const pos = handlers ? handlers.indexOf(cb) : -1; | ||
if (pos > -1) { | ||
(handlers as WindowOpenHandler[]).splice(pos, 1); | ||
} | ||
}; | ||
} | ||
|
||
function monkeyPatchWindowOpen(): void { | ||
fill(WINDOW, 'open', function (originalWindowOpen: () => void): () => void { | ||
return function (...args: unknown[]): void { | ||
if (handlers) { | ||
try { | ||
handlers.forEach(handler => handler()); | ||
} catch (e) { | ||
// ignore errors in here | ||
} | ||
} | ||
|
||
return originalWindowOpen.apply(WINDOW, args); | ||
}; | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we test that the original
window.open
still works?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that makes sense! Will test this as well.