diff --git a/package.json b/package.json index d3733ac..93ab44d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hyperbrowser/sdk", - "version": "1.5.5", + "version": "1.5.6", "description": "Node SDK for Hyperbrowser API", "author": "", "repository": { diff --git a/src/types/web/common.ts b/src/types/web/common.ts index b7bbe20..76c72ce 100644 --- a/src/types/web/common.ts +++ b/src/types/web/common.ts @@ -32,6 +32,16 @@ export interface PageData { status: PageStatus; error?: string; metadata?: Record; + /** + * HTTP status of the page the content came from. Absent when the browser + * received no response. + */ + statusCode?: number; + /** + * URL the page ended on after redirects. For a document such as a PDF, the + * URL of the downloaded file. + */ + finalUrl?: string; markdown?: string; html?: string; links?: string[]; diff --git a/src/types/web/fetch.ts b/src/types/web/fetch.ts index ae0573b..b3f8eaf 100644 --- a/src/types/web/fetch.ts +++ b/src/types/web/fetch.ts @@ -20,6 +20,16 @@ export interface FetchParams { export interface FetchResponseData { metadata?: Record; + /** + * HTTP status of the page the content came from. Absent when the browser + * received no response. + */ + statusCode?: number; + /** + * URL the page ended on after redirects. For a document such as a PDF, the + * URL of the downloaded file. + */ + finalUrl?: string; html?: string; markdown?: string; links?: string[]; diff --git a/tests/unit/public-types-contract.test.ts b/tests/unit/public-types-contract.test.ts index deb6139..d846b85 100644 --- a/tests/unit/public-types-contract.test.ts +++ b/tests/unit/public-types-contract.test.ts @@ -3,6 +3,7 @@ import type { BatchScrapeJobResponse, ClickActionParams, DragActionParams, + FetchResponseData, ScrollActionParams, ScrollAtCursorActionParams, ComputerActionParams, @@ -15,6 +16,7 @@ import type { CreateSessionProfile, GetBatchScrapeJobParams, GetWebCrawlJobParams, + PageData, Sandbox, SandboxExecParams, SandboxImageBuildInputFormat, @@ -164,6 +166,23 @@ describe("public type compatibility", () => { expectTypeOf().toEqualTypeOf(); }); + test("exposes the HTTP status and final URL of fetched pages as optional fields", () => { + const withoutStatusFields: FetchResponseData = { markdown: "# Title" }; + const blockedPage: PageData = { + url: "https://example.com/old", + status: "completed", + statusCode: 403, + finalUrl: "https://example.com/blocked", + }; + + expect(withoutStatusFields.statusCode).toBeUndefined(); + expect(blockedPage.statusCode).toBe(403); + expectTypeOf().toEqualTypeOf(); + expectTypeOf().toEqualTypeOf(); + expectTypeOf().toEqualTypeOf(); + expectTypeOf().toEqualTypeOf(); + }); + test("includes public server region and status values", () => { const region: SessionRegion = "us"; const status: SessionStatus = "close-error";