Handle negative ids in rrdom correctly + extra tests (#927)
* inline stylesheets when loaded * set empty link elements to loaded by default * Clean up stylesheet manager * Remove attribute mutation code * Update packages/rrweb/test/record.test.ts * Update packages/rrweb/test/record.test.ts * Update packages/rrweb/test/record.test.ts * Update packages/rrweb/scripts/repl.js * Update packages/rrweb/test/record.test.ts * Update packages/rrweb/src/record/index.ts * Add todo * Move require out of time sensitive assert * Add waitForRAF, its more reliable than waitForTimeout * Remove flaky tests * Add recording stylesheets in iframes * Remove variability from flaky test * Make test more robust * Fix naming * Add test cases for inlineImages * Add test cases for inlineImages * Record iframe mutations cross page * Test: should record images inside iframe with blob url after iframe was reloaded * Handle negative ids in rrdom correctly When iframes get inserted they create untracked elements, both on the dom and rrdom side. Because they are untracked they generate negative numbers when fetching the id from mirror. This creates a problem when comparing and fetching ids across mirrors. This commit tries to get away from using negative ids as much as possible in rrdom's comparisons * Update packages/rrdom/src/diff.ts Co-authored-by: Yun Feng <yun.feng@anu.edu.au> * Start unserialized nodes at -2 This way we don't accidentally think of them as mirror misses * Set unserialized id starting number at -2 * Remove duplication Co-authored-by: Yun Feng <yun.feng@anu.edu.au>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -207,6 +208,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) {
|
||||
|
||||
Reference in New Issue
Block a user