mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-14 03:55:55 +08:00
fix(scrapeURL/fire-engine): perform format screenshot after specified actions (#1192)
This commit is contained in:
parent
7ecbff3b20
commit
445b906af1
@ -88,5 +88,27 @@ describe("Scrape tests", () => {
|
|||||||
const obj = JSON.parse(response.body.data.rawHtml);
|
const obj = JSON.parse(response.body.data.rawHtml);
|
||||||
expect(obj.id).toBe(1);
|
expect(obj.id).toBe(1);
|
||||||
}, 25000); // TODO: mock and shorten
|
}, 25000); // TODO: mock and shorten
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Screenshot", () => {
|
||||||
|
it.concurrent("screenshot format works", async () => {
|
||||||
|
const response = await scrape({
|
||||||
|
url: "http://firecrawl.dev",
|
||||||
|
formats: ["screenshot"]
|
||||||
|
});
|
||||||
|
|
||||||
|
expectScrapeToSucceed(response);
|
||||||
|
expect(response.body.data.screenshot).toBeTruthy();
|
||||||
|
}, 15000);
|
||||||
|
|
||||||
|
it.concurrent("screenshot@fullPage format works", async () => {
|
||||||
|
const response = await scrape({
|
||||||
|
url: "http://firecrawl.dev",
|
||||||
|
formats: ["screenshot@fullPage"]
|
||||||
|
});
|
||||||
|
|
||||||
|
expectScrapeToSucceed(response);
|
||||||
|
expect(response.body.data.screenshot).toBeTruthy();
|
||||||
|
}, 15000);
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -167,6 +167,9 @@ export async function scrapeURLWithFireEngineChromeCDP(
|
|||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
|
|
||||||
|
// Include specified actions
|
||||||
|
...(meta.options.actions ?? []),
|
||||||
|
|
||||||
// Transform screenshot format into an action (unsupported by chrome-cdp)
|
// Transform screenshot format into an action (unsupported by chrome-cdp)
|
||||||
...(meta.options.formats.includes("screenshot") ||
|
...(meta.options.formats.includes("screenshot") ||
|
||||||
meta.options.formats.includes("screenshot@fullPage")
|
meta.options.formats.includes("screenshot@fullPage")
|
||||||
@ -177,9 +180,6 @@ export async function scrapeURLWithFireEngineChromeCDP(
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
|
|
||||||
// Include specified actions
|
|
||||||
...(meta.options.actions ?? []),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const totalWait = actions.reduce(
|
const totalWait = actions.reduce(
|
||||||
@ -228,8 +228,10 @@ export async function scrapeURLWithFireEngineChromeCDP(
|
|||||||
"Transforming screenshots from actions into screenshot field",
|
"Transforming screenshots from actions into screenshot field",
|
||||||
{ screenshots: response.screenshots },
|
{ screenshots: response.screenshots },
|
||||||
);
|
);
|
||||||
response.screenshot = (response.screenshots ?? [])[0];
|
if (response.screenshots) {
|
||||||
(response.screenshots ?? []).splice(0, 1);
|
response.screenshot = response.screenshots.slice(-1, 0)[0];
|
||||||
|
response.screenshots = response.screenshots.slice(0, -1);
|
||||||
|
}
|
||||||
meta.logger.debug("Screenshot transformation done", {
|
meta.logger.debug("Screenshot transformation done", {
|
||||||
screenshots: response.screenshots,
|
screenshots: response.screenshots,
|
||||||
screenshot: response.screenshot,
|
screenshot: response.screenshot,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user