Skip to content
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
7 changes: 7 additions & 0 deletions packages/browser/src/client/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export class IframeOrchestrator {
constructor() {
debug('init orchestrator', getBrowserState().sessionId)

if (getConfig().browser.traceView.enabled) {
const domSnapshot = import('rrweb-snapshot')
// a load failure surfaces in the tester that awaits this
domSnapshot.catch(() => {})
getBrowserState().browserTraceDomSnapshotPromise = domSnapshot
Comment thread
hi-ogawa marked this conversation as resolved.
Resolved
}

const otelConfig = getBrowserState().config.experimental.openTelemetry
this.traces = new Traces({
enabled: !!(otelConfig?.enabled && otelConfig.browserSdkPath),
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/client/tester/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
} from 'vitest/internal/browser'
import { createStackString, parseStacktrace } from '../../../../utils/src/source-map'
import { getTestName } from '../../../../vitest/src/utils/tasks'
import { getBrowserState, getWorkerState, moduleRunner, now } from '../utils'
import { getBrowserState, getOrchestratorState, getWorkerState, moduleRunner, now } from '../utils'
import { rpc } from './rpc'
import { VitestBrowserSnapshotEnvironment } from './snapshot'
import { recordBrowserTraceEntry } from './trace'
Expand Down Expand Up @@ -92,7 +92,7 @@ function createBrowserRunner(
return
}
if (shouldTraceView) {
getBrowserState().browserTraceDomSnapshot = await import('rrweb-snapshot')
getBrowserState().browserTraceDomSnapshot ??= await getOrchestratorState().browserTraceDomSnapshotPromise
getBrowserState().browserTraceAttempts.set(test.id, { retry, repeats, startTime: now() })
}
else {
Expand Down
8 changes: 8 additions & 0 deletions packages/browser/src/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export interface BrowserRunnerState {
browserTraceAttempts: Map<string, BrowserTraceAttempt>
// lazily loaded only when traceView is enabled
browserTraceDomSnapshot?: typeof import('rrweb-snapshot')
// import started by the orchestrator so every tester reuses one module instance
browserTraceDomSnapshotPromise?: Promise<typeof import('rrweb-snapshot')>
selectorEngine: Ivya
traces: Traces
cleanups: Array<() => unknown>
Expand All @@ -117,6 +119,12 @@ export function getBrowserState(): BrowserRunnerState {
return window.__vitest_browser_runner__
}

/* @__NO_SIDE_EFFECTS__ */
export function getOrchestratorState(): BrowserRunnerState {
// @ts-expect-error not typed global
return window.parent.__vitest_browser_runner__
}

/* @__NO_SIDE_EFFECTS__ */
export function getWorkerState(): WorkerGlobalState {
// @ts-expect-error not typed global
Expand Down
43 changes: 42 additions & 1 deletion patches/rrweb-snapshot@2.1.1.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
diff --git a/dist/rrweb-snapshot.js b/dist/rrweb-snapshot.js
index 1c0fc62d7ede018a7797d3e707c73fa803166d2d..eadcceb088ac1deef08655eb2ed1cdb95fdb515b 100644
--- a/dist/rrweb-snapshot.js
+++ b/dist/rrweb-snapshot.js
@@ -1536,6 +1536,18 @@ const pseudoClassPlugin = {
@@ -603,7 +603,7 @@ function genId() {
return _id++;
}
function getValidTagName(element) {
- if (element instanceof HTMLFormElement) {
+ if (Object.prototype.toString.call(element) === "[object HTMLFormElement]") {
return "form";
}
const processedTagName = toLowerCase(element.tagName);
@@ -612,8 +612,16 @@ function getValidTagName(element) {
}
return processedTagName;
}
-let canvasService;
-let canvasCtx;
+const canvasServices = new WeakMap();
+function getCanvasService(doc) {
+ let service = canvasServices.get(doc);
+ if (!service) {
+ const canvas = doc.createElement("canvas");
+ service = { canvas, context: canvas.getContext("2d") };
+ canvasServices.set(doc, service);
+ }
+ return service;
+}
const SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
const SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
function getAbsoluteSrcsetString(doc, attributeValue) {
@@ -1056,10 +1064,7 @@ function serializeElementNode(n, options) {
}
}
if (tagName === "img" && inlineImages) {
- if (!canvasService) {
- canvasService = doc.createElement("canvas");
- canvasCtx = canvasService.getContext("2d");
- }
+ const { canvas: canvasService, context: canvasCtx } = getCanvasService(doc);
const image = n;
const imageSrc = image.currentSrc || image.getAttribute("src") || "<unknown-src>";
const priorCrossOrigin = image.crossOrigin;
@@ -1536,6 +1541,18 @@ const pseudoClassPlugin = {
if (selector.includes(":hover")) {
rule2.selector += ",\n" + selector.replace(/:hover/g, ".\\:hover");
}
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading