nomagick commited on
Commit
96ce7f5
·
unverified ·
1 Parent(s): 87a6578

fix: iframe should not actively report snapshot

Browse files
backend/functions/src/services/puppeteer.ts CHANGED
@@ -388,24 +388,26 @@ export class PuppeteerControl extends AsyncService {
388
  });
389
 
390
  await page.evaluateOnNewDocument(`
391
- let lastTextLength = 0;
392
- const handlePageLoad = () => {
393
- if (window.haltSnapshot) {
394
- return;
395
- }
396
- const thisTextLength = (document.body.innerText || '').length;
397
- const deltaLength = Math.abs(thisTextLength - lastTextLength);
398
- if (10 * deltaLength < lastTextLength) {
399
- // Change is not significant
400
- return;
401
- }
402
- const r = giveSnapshot();
403
- window.reportSnapshot(r);
404
- lastTextLength = thisTextLength;
405
- };
406
- setInterval(handlePageLoad, 800);
407
- document.addEventListener('readystatechange', handlePageLoad);
408
- document.addEventListener('load', handlePageLoad);
 
 
409
  `);
410
 
411
  this.snMap.set(page, sn);
 
388
  });
389
 
390
  await page.evaluateOnNewDocument(`
391
+ if (window.self === window.top) {
392
+ let lastTextLength = 0;
393
+ const handlePageLoad = () => {
394
+ if (window.haltSnapshot) {
395
+ return;
396
+ }
397
+ const thisTextLength = (document.body.innerText || '').length;
398
+ const deltaLength = Math.abs(thisTextLength - lastTextLength);
399
+ if (10 * deltaLength < lastTextLength) {
400
+ // Change is not significant
401
+ return;
402
+ }
403
+ const r = giveSnapshot();
404
+ window.reportSnapshot(r);
405
+ lastTextLength = thisTextLength;
406
+ };
407
+ setInterval(handlePageLoad, 800);
408
+ document.addEventListener('readystatechange', handlePageLoad);
409
+ document.addEventListener('load', handlePageLoad);
410
+ }
411
  `);
412
 
413
  this.snMap.set(page, sn);