Skip to content

Commit

Permalink
new apporach
Browse files Browse the repository at this point in the history
  • Loading branch information
amandeepsingh333 committed Feb 3, 2025
1 parent 291fa07 commit 3dcfe61
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
18 changes: 18 additions & 0 deletions packages/core/src/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,24 @@ export class Page {
this.log.debug('Serialize DOM', this.meta);

/* istanbul ignore next: no instrumenting injected code */
await this.eval(async () => {
console.log('Executing pre-serialization command...');
try {
/* eslint-disable-next-line no-undef */
if (PercyDOM.checkForLoader()) {
const waitTime = 2000;
await new Promise(resolve => {
setTimeout(() => {
resolve();
}, waitTime);
});
}
} catch (err) {
const errorMessage = `Error while checking for loader: ${err.message}`;
console.error(errorMessage);
}
});

let capture = await this.eval((_, options) => ({
/* eslint-disable-next-line no-undef */
domSnapshot: PercyDOM.serialize(options),
Expand Down
1 change: 1 addition & 0 deletions packages/dom/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export {
} from './serialize-dom';

export { loadAllSrcsetLinks } from './serialize-image-srcset';
export { checkForLoader } from './check-dom-loader';
15 changes: 1 addition & 14 deletions packages/dom/src/serialize-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import serializeCSSOM from './serialize-cssom';
import serializeCanvas from './serialize-canvas';
import serializeVideos from './serialize-video';
import { cloneNodeAndShadow, getOuterHTML } from './clone-dom';
import { checkForLoader } from './check-dom-loader';

// Returns a copy or new doctype for a document.
function doctype(dom) {
Expand Down Expand Up @@ -97,22 +96,10 @@ export function serializeDOM(options) {
enableJavaScript,
disableShadowDOM
};

ctx.dom = dom;
ctx.clone = cloneNodeAndShadow(ctx);

try {
if (checkForLoader()) {
const startTime = Date.now();
const waitTime = 2000;
while (Date.now() - startTime < waitTime) {
// pass
}
}
} catch (err) {
const errorMessage = `Error while checking for loader: ${err.message}`;
ctx.warnings.add(errorMessage);
console.error(errorMessage);
}
serializeElements(ctx);

if (domTransformation) {
Expand Down

0 comments on commit 3dcfe61

Please sign in to comment.