add option to record on DOMContentLoaded event (#1109)

This commit is contained in:
Yun Feng
2023-02-09 20:14:49 +11:00
committed by GitHub
parent 07d22e7cd9
commit 0627d4df7c
7 changed files with 117 additions and 11 deletions

View File

@@ -76,6 +76,9 @@ function record<T = eventWithTime>(
mousemoveWait,
recordCanvas = false,
recordCrossOriginIframes = false,
recordAfter = options.recordAfter === 'DOMContentLoaded'
? options.recordAfter
: 'load',
userTriggeredOnInput = false,
collectFonts = false,
inlineImages = false,
@@ -408,16 +411,6 @@ function record<T = eventWithTime>(
try {
const handlers: listenerHandler[] = [];
handlers.push(
on('DOMContentLoaded', () => {
wrappedEmit(
wrapEvent({
type: EventType.DomContentLoaded,
data: {},
}),
);
}),
);
const observe = (doc: Document) => {
return initObservers(
@@ -583,6 +576,17 @@ function record<T = eventWithTime>(
) {
init();
} else {
handlers.push(
on('DOMContentLoaded', () => {
wrappedEmit(
wrapEvent({
type: EventType.DomContentLoaded,
data: {},
}),
);
if (recordAfter === 'DOMContentLoaded') init();
}),
);
handlers.push(
on(
'load',
@@ -593,7 +597,7 @@ function record<T = eventWithTime>(
data: {},
}),
);
init();
if (recordAfter === 'load') init();
},
window,
),

View File

@@ -61,6 +61,7 @@ export type recordOptions<T> = {
dataURLOptions?: DataURLOptions;
recordCanvas?: boolean;
recordCrossOriginIframes?: boolean;
recordAfter?: 'DOMContentLoaded' | 'load';
userTriggeredOnInput?: boolean;
collectFonts?: boolean;
inlineImages?: boolean;

View File

@@ -8408,6 +8408,89 @@ exports[`record integration tests should record DOM node movement 2 1`] = `
]"
`;
exports[`record integration tests should record after DOMContentLoaded event 1`] = `
"[
{
\\"type\\": 0,
\\"data\\": {}
},
{
\\"type\\": 4,
\\"data\\": {
\\"href\\": \\"about:blank\\",
\\"width\\": 1920,
\\"height\\": 1080
}
},
{
\\"type\\": 2,
\\"data\\": {
\\"node\\": {
\\"type\\": 0,
\\"childNodes\\": [
{
\\"type\\": 2,
\\"tagName\\": \\"html\\",
\\"attributes\\": {},
\\"childNodes\\": [
{
\\"type\\": 2,
\\"tagName\\": \\"head\\",
\\"attributes\\": {},
\\"childNodes\\": [],
\\"id\\": 3
},
{
\\"type\\": 2,
\\"tagName\\": \\"body\\",
\\"attributes\\": {},
\\"childNodes\\": [
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n \\",
\\"id\\": 5
},
{
\\"type\\": 2,
\\"tagName\\": \\"script\\",
\\"attributes\\": {},
\\"childNodes\\": [
{
\\"type\\": 3,
\\"textContent\\": \\"SCRIPT_PLACEHOLDER\\",
\\"id\\": 7
}
],
\\"id\\": 6
},
{
\\"type\\": 3,
\\"textContent\\": \\"\\\\n \\\\n \\\\n\\\\n\\",
\\"id\\": 8
}
],
\\"id\\": 4
}
],
\\"id\\": 2
}
],
\\"compatMode\\": \\"BackCompat\\",
\\"id\\": 1
},
\\"initialOffset\\": {
\\"left\\": 0,
\\"top\\": 0
}
}
},
{
\\"type\\": 1,
\\"data\\": {}
}
]"
`;
exports[`record integration tests should record canvas mutations 1`] = `
"[
{

View File

@@ -984,4 +984,19 @@ describe('record integration tests', function (this: ISuite) {
)) as eventWithTime[];
assertSnapshot(snapshots);
});
it('should record after DOMContentLoaded event', async () => {
const page: puppeteer.Page = await browser.newPage();
await page.goto('about:blank');
await page.setContent(
getHtml.call(this, 'blank.html', {
recordAfter: 'DOMContentLoaded',
}),
);
const snapshots = (await page.evaluate(
'window.snapshots',
)) as eventWithTime[];
assertSnapshot(snapshots);
});
});

View File

@@ -601,6 +601,7 @@ export function generateRecordSnippet(options: recordOptions<eventWithTime>) {
userTriggeredOnInput: ${options.userTriggeredOnInput},
maskTextFn: ${options.maskTextFn},
recordCanvas: ${options.recordCanvas},
recordAfter: '${options.recordAfter || 'load'}',
inlineImages: ${options.inlineImages},
plugins: ${options.plugins}
});