mirror of
https://github.com/intergalacticalvariable/reader.git
synced 2024-11-16 11:42:32 +08:00
fix: reduce frequency of screenshot if possible
This commit is contained in:
parent
ae99af50aa
commit
94a72052f4
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user