Skip to content
Open
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
10 changes: 10 additions & 0 deletions .changeset/cuddly-dolphins-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@rrweb/all": patch
"@rrweb/packer": patch
"@rrweb/record": patch
"rrweb-snapshot": patch
"rrweb": patch
"@rrweb/web-extension": patch
---

Drop base64 inlined worker source from all bundles
3 changes: 3 additions & 0 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
- name: Build Project
run: NODE_OPTIONS='--max-old-space-size=4096' yarn build:all

- name: Install Playwright browsers
run: cd packages/rrvideo && yarn playwright install chromium

- name: Check types
run: yarn check-types

Expand Down
2 changes: 1 addition & 1 deletion packages/all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
],
"devDependencies": {
"puppeteer": "^20.9.0",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.4.0",
"typescript": "^5.4.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/packer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"package.json"
],
"devDependencies": {
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.4.0",
"typescript": "^5.4.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"devDependencies": {
"rrweb": "^2.0.0-alpha.19",
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"devDependencies": {
"rrweb": "^2.0.0-alpha.19",
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/rrweb-plugin-console-record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"devDependencies": {
"rrweb": "^2.0.0-alpha.19",
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.4.0",
"puppeteer": "^20.9.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/rrweb-plugin-console-replay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@rrweb/rrweb-plugin-console-record": "^2.0.0-alpha.19",
"rrweb": "^2.0.0-alpha.19",
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"devDependencies": {
"rrweb": "^2.0.0-alpha.19",
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@rrweb/rrweb-plugin-sequential-id-record": "^2.0.0-alpha.19",
"rrweb": "^2.0.0-alpha.19",
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
],
"devDependencies": {
"puppeteer": "^20.9.0",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.4.0",
"typescript": "^5.4.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/replay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
],
"devDependencies": {
"puppeteer": "^20.9.0",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.4.0",
"typescript": "^5.4.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/rrdom-nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"compare-versions": "^4.1.3",
"eslint": "^8.15.0",
"puppeteer": "^9.1.1",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.4.0",
"typescript": "^5.4.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/rrdom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"eslint": "^8.15.0",
"puppeteer": "^17.1.3",
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1"
},
"dependencies": {
Expand Down
100 changes: 78 additions & 22 deletions packages/rrvideo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,29 @@ function getHtml(events: Array<eventWithTime>, config?: RRvideoConfig): string {
)};
/*-->*/
const userConfig = ${JSON.stringify(config?.rrwebPlayer || {})};
window.replayer = new rrwebPlayer.Player({
target: document.body,
width: userConfig.width,
height: userConfig.height,
props: {
...userConfig,
events,
showController: false,
},
});
window.replayer.addEventListener('finish', () => window.onReplayFinish());
window.replayer.addEventListener('ui-update-progress', (payload)=> window.onReplayProgressUpdate
(payload));
window.replayer.addEventListener('resize',()=>document.querySelector('.replayer-wrapper').style.transform = 'scale(${
(config?.resolutionRatio ?? 1) * MaxScaleValue
}) translate(-50%, -50%)');
try {
window.replayer = new rrwebPlayer({
target: document.body,
props: {
width: userConfig.width,
height: userConfig.height,
...userConfig,
events,
showController: false,
autoPlay: false,
},
});
window.replayer.addEventListener('finish', () => window.onReplayFinish());
window.replayer.addEventListener('ui-update-progress', (payload)=> window.onReplayProgressUpdate(payload));
window.replayer.addEventListener('resize',()=>document.querySelector('.replayer-wrapper').style.transform = 'scale(${
(config?.resolutionRatio ?? 1) * MaxScaleValue
}) translate(-50%, -50%)');
// Start playback after event listeners are attached
window.replayer.play();
} catch (error) {
console.error('Error initializing replayer:', error);
window.onReplayFinish();
}
</script>
</body>
</html>
Expand Down Expand Up @@ -105,18 +112,21 @@ export async function transformToVideo(options: RRvideoConfig) {
Object.assign(config, options);
if (config.resolutionRatio > 1) config.resolutionRatio = 1; // The max value is 1.

console.log('[DEBUG] Starting transformToVideo');
const eventsPath = path.isAbsolute(config.input)
? config.input
: path.resolve(process.cwd(), config.input);
const outputPath = path.isAbsolute(config.output)
? config.output
: path.resolve(process.cwd(), config.output);
console.log('[DEBUG] Reading events from:', eventsPath);
const events = JSON.parse(
fs.readFileSync(eventsPath, 'utf-8'),
) as eventWithTime[];

// Make the browser viewport fit the player size.
const maxViewport = getMaxViewport(events);
console.log('[DEBUG] Max viewport:', maxViewport);
// Use the scaling method to improve the video quality.
const scaledViewport = {
width: Math.round(
Expand All @@ -127,18 +137,39 @@ export async function transformToVideo(options: RRvideoConfig) {
),
};
Object.assign(config.rrwebPlayer, scaledViewport);
console.log('[DEBUG] Launching browser with headless:', config.headless);
const browser = await chromium.launch({
headless: config.headless,
});
console.log('[DEBUG] Browser launched successfully');
console.log(
'[DEBUG] Creating browser context with viewport:',
scaledViewport,
);
const context = await browser.newContext({
viewport: scaledViewport,
recordVideo: {
dir: defaultVideoDir,
size: scaledViewport,
},
});
console.log('[DEBUG] Browser context created');
const page = await context.newPage();
console.log('[DEBUG] New page created');
await page.goto('about:blank');
console.log('[DEBUG] Navigated to about:blank');
console.log('[DEBUG] Exposing functions to page');

// Listen to console messages from the page
page.on('console', (msg) => {
console.log('[PAGE CONSOLE]', msg.type(), msg.text());
});

// Listen to page errors
page.on('pageerror', (error) => {
console.error('[PAGE ERROR]', error.message);
});

await page.exposeFunction(
'onReplayProgressUpdate',
(data: { payload: number }) => {
Expand All @@ -147,20 +178,44 @@ export async function transformToVideo(options: RRvideoConfig) {
);

// Wait for the replay to finish
await new Promise<void>(
(resolve) =>
void page
.exposeFunction('onReplayFinish', () => resolve())
.then(() => page.setContent(getHtml(events, config))),
);
console.log('[DEBUG] Starting replay');
await new Promise<void>((resolve, reject) => {
const timeout = setTimeout(() => {
console.error('[DEBUG] Replay timeout - finish event never fired');
reject(new Error('Replay timeout'));
}, 120000); // 2 minute timeout

void page
.exposeFunction('onReplayFinish', () => {
console.log('[DEBUG] Replay finished');
clearTimeout(timeout);
resolve();
})
.then(() => {
console.log('[DEBUG] Setting page content');
return page.setContent(getHtml(events, config));
})
.then(() => {
console.log('[DEBUG] Page content set successfully');
})
.catch((err) => {
console.error('[DEBUG] Error setting page content:', err);
clearTimeout(timeout);
reject(err);
});
});
console.log('[DEBUG] Getting video path');
const videoPath = (await page.video()?.path()) || '';
console.log('[DEBUG] Video path:', videoPath);
const cleanFiles = async (videoPath: string) => {
await fs.remove(videoPath);
if ((await fs.readdir(defaultVideoDir)).length === 0) {
await fs.remove(defaultVideoDir);
}
};
console.log('[DEBUG] Closing context');
await context.close();
console.log('[DEBUG] Moving video file to output path:', outputPath);
await Promise.all([
fs
.move(videoPath, outputPath, { overwrite: true })
Expand All @@ -173,5 +228,6 @@ export async function transformToVideo(options: RRvideoConfig) {
.finally(() => void cleanFiles(videoPath)),
browser.close(),
]);
console.log('[DEBUG] Video transformation complete');
return outputPath;
}
9 changes: 5 additions & 4 deletions packages/rrvideo/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ describe('should be able to run cli', () => {
await fs.remove(path.resolve(__dirname, './generated'));
});

const execOptions = { stdio: 'pipe', timeout: 60_000 } as const;
const execOptions = { timeout: 60_000 } as const;
const execOptionsWithOutput = { ...execOptions, stdio: 'inherit' } as const;

it('should throw error without input path', () => {
expect(() => {
execSync('node ./build/cli.js', execOptions);
execSync('node ./build/cli.js', { ...execOptions, stdio: 'pipe' });
}).toThrowError(/.*please pass --input to your rrweb events file.*/);
});

it('should generate a video without output path', () => {
execSync(
'node ./build/cli.js --input ./test/generated/example.json',
execOptions,
execOptionsWithOutput,
);
const outputFile = path.resolve(__dirname, '../rrvideo-output.webm');
expect(fs.existsSync(outputFile)).toBe(true);
Expand All @@ -40,7 +41,7 @@ describe('should be able to run cli', () => {
const outputFile = path.resolve(__dirname, './generated/output.webm');
execSync(
`node ./build/cli.js --input ./test/generated/example.json --output ${outputFile}`,
execOptions,
execOptionsWithOutput,
);
expect(fs.existsSync(outputFile)).toBe(true);
fs.removeSync(outputFile);
Expand Down
2 changes: 1 addition & 1 deletion packages/rrweb-player/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"svelte-preprocess": "^5.0.3",
"svelte2tsx": "^0.7.30",
"tslib": "^2.0.0",
"vite": "^5.3.1"
"vite": "^6.0.1"
},
"dependencies": {
"@tsconfig/svelte": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/rrweb-snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"ts-node": "^7.0.1",
"tslib": "^1.9.3",
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.4.0"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/rrweb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"default": "./dist/rrweb.cjs"
}
},
"./dist/rrweb.css": "./dist/rrweb.css",
"./dist/style.css": "./dist/style.css"
},
"files": [
Expand Down Expand Up @@ -76,7 +77,7 @@
"ts-node": "^10.9.1",
"tslib": "^2.3.1",
"typescript": "^5.4.5",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"package.json"
],
"devDependencies": {
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.9.1"
},
"browserslist": [
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"package.json"
],
"devDependencies": {
"vite": "^5.2.8",
"vite": "^6.0.1",
"vite-plugin-dts": "^3.8.1"
},
"dependencies": {}
Expand Down
2 changes: 1 addition & 1 deletion packages/web-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@vitejs/plugin-react": "^4.2.1",
"semver": "^7.6.3",
"type-fest": "^2.19.0",
"vite": "^5.3.1",
"vite": "^6.0.1",
"vite-plugin-web-extension": "^4.1.3",
"vite-plugin-zip-pack": "^1.2.2",
"webextension-polyfill": "^0.10.0"
Expand Down
Loading
Loading