mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-11 23:49:02 +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?: {
|
actions?: {
|
||||||
screenshots?: string[];
|
screenshots?: string[];
|
||||||
scrapes?: ScrapeActionContent[];
|
scrapes?: ScrapeActionContent[];
|
||||||
|
javascriptReturns?: {
|
||||||
|
type: string,
|
||||||
|
value: unknown
|
||||||
|
}[];
|
||||||
};
|
};
|
||||||
metadata: {
|
metadata: {
|
||||||
title?: string;
|
title?: string;
|
||||||
|
@ -42,6 +42,36 @@ const successSchema = z.object({
|
|||||||
})
|
})
|
||||||
.array()
|
.array()
|
||||||
.optional(),
|
.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
|
// chrome-cdp only -- file download handler
|
||||||
file: z
|
file: z
|
||||||
@ -138,7 +168,7 @@ export async function fireEngineCheckStatus(
|
|||||||
} else if (
|
} else if (
|
||||||
typeof status.error === "string" &&
|
typeof status.error === "string" &&
|
||||||
// TODO: improve this later
|
// 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]);
|
throw new ActionError(status.error.split("Error: ")[1]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -274,6 +274,7 @@ export async function scrapeURLWithFireEngineChromeCDP(
|
|||||||
actions: {
|
actions: {
|
||||||
screenshots: response.screenshots ?? [],
|
screenshots: response.screenshots ?? [],
|
||||||
scrapes: response.actionContent ?? [],
|
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?: {
|
actions?: {
|
||||||
screenshots: string[];
|
screenshots: string[];
|
||||||
scrapes: ScrapeActionContent[];
|
scrapes: ScrapeActionContent[];
|
||||||
|
javascriptReturns: {
|
||||||
|
type: string;
|
||||||
|
value: unknown
|
||||||
|
}[];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -141,6 +141,14 @@ export interface ScrapeParams<LLMSchema extends zt.ZodSchema = any, ActionsSchem
|
|||||||
|
|
||||||
export interface ActionsResult {
|
export interface ActionsResult {
|
||||||
screenshots: string[];
|
screenshots: string[];
|
||||||
|
scrapes: ({
|
||||||
|
url: string;
|
||||||
|
html: string;
|
||||||
|
})[];
|
||||||
|
javascriptReturns: {
|
||||||
|
type: string;
|
||||||
|
value: unknown
|
||||||
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user