|
1 | | -import type { RecordingEvent, ReplayContainer } from '@sentry/replay/build/npm/types/types'; |
| 1 | +import type { |
| 2 | + RecordingEvent, |
| 3 | + ReplayContainer, |
| 4 | + InternalEventContext, |
| 5 | + Session, |
| 6 | +} from '@sentry/replay/build/npm/types/types'; |
2 | 7 | import type { Breadcrumb, Event, ReplayEvent } from '@sentry/types'; |
3 | 8 | import pako from 'pako'; |
4 | 9 | import type { Page, Request, Response } from 'playwright'; |
@@ -73,9 +78,22 @@ export function isReplayEvent(event: Event): event is ReplayEvent { |
73 | 78 | * Note that due to how this works with playwright, this is a POJO copy of replay. |
74 | 79 | * This means that we cannot access any methods on it, and also not mutate it in any way. |
75 | 80 | */ |
76 | | -export async function getReplaySnapshot(page: Page): Promise<ReplayContainer> { |
77 | | - const replayIntegration = await page.evaluate<{ _replay: ReplayContainer }>('window.Replay'); |
78 | | - return replayIntegration._replay; |
| 81 | +export async function getReplaySnapshot( |
| 82 | + page: Page, |
| 83 | +): Promise<{ _isPaused: boolean; _isEnabled: boolean; _context: InternalEventContext; session: Session | undefined }> { |
| 84 | + return await page.evaluate(() => { |
| 85 | + const replayIntegration = (window as unknown as Window & { Replay: { _replay: ReplayContainer } }).Replay; |
| 86 | + const replay = replayIntegration._replay; |
| 87 | + |
| 88 | + const replaySnapshot = { |
| 89 | + _isPaused: replay.isPaused(), |
| 90 | + _isEnabled: replay.isEnabled(), |
| 91 | + _context: replay.getContext(), |
| 92 | + session: replay.session, |
| 93 | + }; |
| 94 | + |
| 95 | + return replaySnapshot; |
| 96 | + }); |
79 | 97 | } |
80 | 98 |
|
81 | 99 | export const REPLAY_DEFAULT_FLUSH_MAX_DELAY = 5_000; |
|
0 commit comments