Spaces:
Build error
Build error
fix: reduce frequency of screenshot if possible
Browse files
backend/functions/src/cloud-functions/crawler.ts
CHANGED
|
@@ -309,6 +309,7 @@ ${this.content}
|
|
| 309 |
const crawlOpts: ScrappingOptions = {
|
| 310 |
proxyUrl: ctx.req.get('x-proxy-url'),
|
| 311 |
cookies,
|
|
|
|
| 312 |
};
|
| 313 |
|
| 314 |
if (!ctx.req.accepts('text/plain') && ctx.req.accepts('text/event-stream')) {
|
|
@@ -418,6 +419,7 @@ ${this.content}
|
|
| 418 |
|
| 419 |
return {
|
| 420 |
isFresh: !stale,
|
|
|
|
| 421 |
snapshot: {
|
| 422 |
...r,
|
| 423 |
screenshot: undefined,
|
|
@@ -471,7 +473,7 @@ ${this.content}
|
|
| 471 |
cache = await this.queryCache(urlToCrawl);
|
| 472 |
}
|
| 473 |
|
| 474 |
-
if (cache?.isFresh) {
|
| 475 |
yield cache.snapshot;
|
| 476 |
|
| 477 |
return;
|
|
|
|
| 309 |
const crawlOpts: ScrappingOptions = {
|
| 310 |
proxyUrl: ctx.req.get('x-proxy-url'),
|
| 311 |
cookies,
|
| 312 |
+
favorScreenshot: customMode === 'screenshot'
|
| 313 |
};
|
| 314 |
|
| 315 |
if (!ctx.req.accepts('text/plain') && ctx.req.accepts('text/event-stream')) {
|
|
|
|
| 419 |
|
| 420 |
return {
|
| 421 |
isFresh: !stale,
|
| 422 |
+
...cache,
|
| 423 |
snapshot: {
|
| 424 |
...r,
|
| 425 |
screenshot: undefined,
|
|
|
|
| 473 |
cache = await this.queryCache(urlToCrawl);
|
| 474 |
}
|
| 475 |
|
| 476 |
+
if (cache?.isFresh && (!crawlOpts.favorScreenshot || (crawlOpts.favorScreenshot && cache?.screenshotAvailable))) {
|
| 477 |
yield cache.snapshot;
|
| 478 |
|
| 479 |
return;
|
backend/functions/src/services/puppeteer.ts
CHANGED
|
@@ -50,6 +50,7 @@ export interface PageSnapshot {
|
|
| 50 |
export interface ScrappingOptions {
|
| 51 |
proxyUrl?: string;
|
| 52 |
cookies?: CookieParam[];
|
|
|
|
| 53 |
}
|
| 54 |
|
| 55 |
|
|
@@ -289,7 +290,7 @@ document.addEventListener('load', handlePageLoad);
|
|
| 289 |
yield { ...snapshot, screenshot } as PageSnapshot;
|
| 290 |
break;
|
| 291 |
}
|
| 292 |
-
if (snapshot?.title && snapshot?.html !== lastHTML) {
|
| 293 |
screenshot = await page.screenshot();
|
| 294 |
lastHTML = snapshot.html;
|
| 295 |
}
|
|
|
|
| 50 |
export interface ScrappingOptions {
|
| 51 |
proxyUrl?: string;
|
| 52 |
cookies?: CookieParam[];
|
| 53 |
+
favorScreenshot?: boolean;
|
| 54 |
}
|
| 55 |
|
| 56 |
|
|
|
|
| 290 |
yield { ...snapshot, screenshot } as PageSnapshot;
|
| 291 |
break;
|
| 292 |
}
|
| 293 |
+
if (options.favorScreenshot && snapshot?.title && snapshot?.html !== lastHTML) {
|
| 294 |
screenshot = await page.screenshot();
|
| 295 |
lastHTML = snapshot.html;
|
| 296 |
}
|