Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add test cases for inlineImages
  • Loading branch information
Juice10 committed Jun 29, 2022
commit d2cb4112c9d94d53618a866d490b42c70b8e6f8b
5 changes: 5 additions & 0 deletions packages/rrweb-snapshot/test/html/picture-blob-in-frame.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<iframe src="picture-blob.html"></iframe>
</body>
</html>
16 changes: 16 additions & 0 deletions packages/rrweb-snapshot/test/html/picture-blob.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<img src="" alt="This is a robot" />
</body>
<script>
setTimeout(async function () {
const robotFile = await fetch('/images/robot.png');
const robotBlob = await robotFile.blob();
const robotBlobUrl = URL.createObjectURL(robotBlob);
const images = document.querySelectorAll('img');
images.forEach((img) => {
img.src = robotBlobUrl;
});
}, 0);
</script>
</html>
5 changes: 5 additions & 0 deletions packages/rrweb-snapshot/test/html/picture-in-frame.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<iframe src="picture.html"></iframe>
</body>
</html>
69 changes: 69 additions & 0 deletions packages/rrweb-snapshot/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as puppeteer from 'puppeteer';
import * as rollup from 'rollup';
import * as typescript from 'rollup-plugin-typescript2';
import * as assert from 'assert';
import { waitForRAF } from './utils';

const _typescript = (typescript as unknown) as () => rollup.Plugin;

Expand Down Expand Up @@ -209,6 +210,74 @@ iframe.contentDocument.querySelector('center').clientHeight
assert(snapshot.includes('"rr_dataURL"'));
assert(snapshot.includes('data:image/webp;base64,'));
});

it('correctly saves blob:images offline', async () => {
const page: puppeteer.Page = await browser.newPage();

await page.goto('http://localhost:3030/html/picture-blob.html', {
waitUntil: 'load',
});
await page.waitForSelector('img', { timeout: 1000 });
await page.evaluate(`${code}var snapshot = rrweb.snapshot(document, {
dataURLOptions: { type: "image/webp", quality: 0.8 },
inlineImages: true,
inlineStylesheet: false
})`);
await page.waitFor(100);
const snapshot = await page.evaluate('JSON.stringify(snapshot, null, 2);');
assert(snapshot.includes('"rr_dataURL"'));
assert(snapshot.includes('data:image/webp;base64,'));
});

it('correctly saves images in iframes offline', async () => {
const page: puppeteer.Page = await browser.newPage();

await page.goto('http://localhost:3030/html/picture-in-frame.html', {
waitUntil: 'load',
});
await page.waitForSelector('iframe', { timeout: 1000 });
await waitForRAF(page); // wait for page to render
await page.evaluate(`${code}
rrweb.snapshot(document, {
dataURLOptions: { type: "image/webp", quality: 0.8 },
inlineImages: true,
inlineStylesheet: false,
onIframeLoad: function(iframe, sn) {
window.snapshot = sn;
}
})`);
await page.waitFor(100);
const snapshot = await page.evaluate(
'JSON.stringify(window.snapshot, null, 2);',
);
assert(snapshot.includes('"rr_dataURL"'));
assert(snapshot.includes('data:image/webp;base64,'));
});

it('correctly saves blob:images in iframes offline', async () => {
const page: puppeteer.Page = await browser.newPage();

await page.goto('http://localhost:3030/html/picture-blob-in-frame.html', {
waitUntil: 'load',
});
await page.waitForSelector('iframe', { timeout: 1000 });
await waitForRAF(page); // wait for page to render
await page.evaluate(`${code}
rrweb.snapshot(document, {
dataURLOptions: { type: "image/webp", quality: 0.8 },
inlineImages: true,
inlineStylesheet: false,
onIframeLoad: function(iframe, sn) {
window.snapshot = sn;
}
})`);
await page.waitFor(100);
const snapshot = await page.evaluate(
'JSON.stringify(window.snapshot, null, 2);',
);
assert(snapshot.includes('"rr_dataURL"'));
assert(snapshot.includes('data:image/webp;base64,'));
});
});

describe('iframe integration tests', function (this: ISuite) {
Expand Down
11 changes: 11 additions & 0 deletions packages/rrweb-snapshot/test/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as puppeteer from 'puppeteer';

export async function waitForRAF(page: puppeteer.Page) {
return await page.evaluate(() => {
return new Promise((resolve) => {
requestAnimationFrame(() => {
requestAnimationFrame(resolve);
});
});
});
}
Loading