Skip to content

Commit

Permalink
fix: iframe should not actively report snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
nomagick committed Sep 17, 2024
1 parent 87a6578 commit 96ce7f5
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions backend/functions/src/services/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,24 +388,26 @@ export class PuppeteerControl extends AsyncService {
});

await page.evaluateOnNewDocument(`
let lastTextLength = 0;
const handlePageLoad = () => {
if (window.haltSnapshot) {
return;
}
const thisTextLength = (document.body.innerText || '').length;
const deltaLength = Math.abs(thisTextLength - lastTextLength);
if (10 * deltaLength < lastTextLength) {
// Change is not significant
return;
}
const r = giveSnapshot();
window.reportSnapshot(r);
lastTextLength = thisTextLength;
};
setInterval(handlePageLoad, 800);
document.addEventListener('readystatechange', handlePageLoad);
document.addEventListener('load', handlePageLoad);
if (window.self === window.top) {
let lastTextLength = 0;
const handlePageLoad = () => {
if (window.haltSnapshot) {
return;
}
const thisTextLength = (document.body.innerText || '').length;
const deltaLength = Math.abs(thisTextLength - lastTextLength);
if (10 * deltaLength < lastTextLength) {
// Change is not significant
return;
}
const r = giveSnapshot();
window.reportSnapshot(r);
lastTextLength = thisTextLength;
};
setInterval(handlePageLoad, 800);
document.addEventListener('readystatechange', handlePageLoad);
document.addEventListener('load', handlePageLoad);
}
`);

this.snMap.set(page, sn);
Expand Down

0 comments on commit 96ce7f5

Please sign in to comment.