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:
Gergő Móricz 2025-03-28 12:42:25 +01:00 committed by GitHub
parent 56d23cc6ac
commit 46048bc94d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 48 additions and 1 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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)),
}, },
} }
: {}), : {}),

View File

@ -103,6 +103,10 @@ export type EngineScrapeResult = {
actions?: { actions?: {
screenshots: string[]; screenshots: string[];
scrapes: ScrapeActionContent[]; scrapes: ScrapeActionContent[];
javascriptReturns: {
type: string;
value: unknown
}[];
}; };
}; };

View File

@ -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
}[];
} }
/** /**