mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-11 20:58:59 +08:00
feat(scrapeURL): return js returns from f-e (FIR-1535) (#1385)
* feat(scrapeURL): return js returns from f-e * feat(js-sdk): handle new results
This commit is contained in:
parent
56d23cc6ac
commit
46048bc94d
@ -541,6 +541,10 @@ export type Document = {
|
||||
actions?: {
|
||||
screenshots?: string[];
|
||||
scrapes?: ScrapeActionContent[];
|
||||
javascriptReturns?: {
|
||||
type: string,
|
||||
value: unknown
|
||||
}[];
|
||||
};
|
||||
metadata: {
|
||||
title?: string;
|
||||
|
@ -42,6 +42,36 @@ const successSchema = z.object({
|
||||
})
|
||||
.array()
|
||||
.optional(),
|
||||
actionResults: z.union([
|
||||
z.object({
|
||||
idx: z.number(),
|
||||
type: z.literal("screenshot"),
|
||||
result: z.object({
|
||||
path: z.string(),
|
||||
}),
|
||||
}),
|
||||
z.object({
|
||||
idx: z.number(),
|
||||
type: z.literal("scrape"),
|
||||
result: z.union([
|
||||
z.object({
|
||||
url: z.string(),
|
||||
html: z.string(),
|
||||
}),
|
||||
z.object({
|
||||
url: z.string(),
|
||||
accessibility: z.string(),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
z.object({
|
||||
idx: z.number(),
|
||||
type: z.literal("executeJavascript"),
|
||||
result: z.object({
|
||||
return: z.string(),
|
||||
}),
|
||||
}),
|
||||
]).array().optional(),
|
||||
|
||||
// chrome-cdp only -- file download handler
|
||||
file: z
|
||||
@ -138,7 +168,7 @@ export async function fireEngineCheckStatus(
|
||||
} else if (
|
||||
typeof status.error === "string" &&
|
||||
// TODO: improve this later
|
||||
status.error.includes("Element")
|
||||
(status.error.includes("Element") || status.error.includes("Javascript execution failed"))
|
||||
) {
|
||||
throw new ActionError(status.error.split("Error: ")[1]);
|
||||
} else {
|
||||
|
@ -274,6 +274,7 @@ export async function scrapeURLWithFireEngineChromeCDP(
|
||||
actions: {
|
||||
screenshots: response.screenshots ?? [],
|
||||
scrapes: response.actionContent ?? [],
|
||||
javascriptReturns: (response.actionResults ?? []).filter(x => x.type === "executeJavascript").map(x => JSON.parse((x.result as any as { return: string }).return)),
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
|
@ -103,6 +103,10 @@ export type EngineScrapeResult = {
|
||||
actions?: {
|
||||
screenshots: string[];
|
||||
scrapes: ScrapeActionContent[];
|
||||
javascriptReturns: {
|
||||
type: string;
|
||||
value: unknown
|
||||
}[];
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -141,6 +141,14 @@ export interface ScrapeParams<LLMSchema extends zt.ZodSchema = any, ActionsSchem
|
||||
|
||||
export interface ActionsResult {
|
||||
screenshots: string[];
|
||||
scrapes: ({
|
||||
url: string;
|
||||
html: string;
|
||||
})[];
|
||||
javascriptReturns: {
|
||||
type: string;
|
||||
value: unknown
|
||||
}[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user