fix: reduce frequency of screenshot if possible

This commit is contained in:
yanlong.wang 2024-04-24 19:43:24 +08:00
parent ae99af50aa
commit 94a72052f4
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37
2 changed files with 5 additions and 2 deletions

View File

@ -309,6 +309,7 @@ ${this.content}
const crawlOpts: ScrappingOptions = {
proxyUrl: ctx.req.get('x-proxy-url'),
cookies,
favorScreenshot: customMode === 'screenshot'
};
if (!ctx.req.accepts('text/plain') && ctx.req.accepts('text/event-stream')) {
@ -418,6 +419,7 @@ ${this.content}
return {
isFresh: !stale,
...cache,
snapshot: {
...r,
screenshot: undefined,
@ -471,7 +473,7 @@ ${this.content}
cache = await this.queryCache(urlToCrawl);
}
if (cache?.isFresh) {
if (cache?.isFresh && (!crawlOpts.favorScreenshot || (crawlOpts.favorScreenshot && cache?.screenshotAvailable))) {
yield cache.snapshot;
return;

View File

@ -50,6 +50,7 @@ export interface PageSnapshot {
export interface ScrappingOptions {
proxyUrl?: string;
cookies?: CookieParam[];
favorScreenshot?: boolean;
}
@ -289,7 +290,7 @@ document.addEventListener('load', handlePageLoad);
yield { ...snapshot, screenshot } as PageSnapshot;
break;
}
if (snapshot?.title && snapshot?.html !== lastHTML) {
if (options.favorScreenshot && snapshot?.title && snapshot?.html !== lastHTML) {
screenshot = await page.screenshot();
lastHTML = snapshot.html;
}