mirror of
https://git.mirrors.martin98.com/https://github.com/jina-ai/reader.git
synced 2025-08-19 05:15:57 +08:00
fix: iframe should not actively report snapshot
This commit is contained in:
parent
87a6578970
commit
96ce7f5aac
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user