Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hyperbrowser/sdk",
"version": "1.5.5",
"version": "1.5.6",
"description": "Node SDK for Hyperbrowser API",
"author": "",
"repository": {
Expand Down
10 changes: 10 additions & 0 deletions src/types/web/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ export interface PageData {
status: PageStatus;
error?: string;
metadata?: Record<string, unknown>;
/**
* 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[];
Expand Down
10 changes: 10 additions & 0 deletions src/types/web/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export interface FetchParams {

export interface FetchResponseData {
metadata?: Record<string, unknown>;
/**
* 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[];
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/public-types-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
BatchScrapeJobResponse,
ClickActionParams,
DragActionParams,
FetchResponseData,
ScrollActionParams,
ScrollAtCursorActionParams,
ComputerActionParams,
Expand All @@ -15,6 +16,7 @@ import type {
CreateSessionProfile,
GetBatchScrapeJobParams,
GetWebCrawlJobParams,
PageData,
Sandbox,
SandboxExecParams,
SandboxImageBuildInputFormat,
Expand Down Expand Up @@ -164,6 +166,23 @@ describe("public type compatibility", () => {
expectTypeOf<Sandbox["network"]>().toEqualTypeOf<SandboxNetworkPolicy | null | undefined>();
});

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<FetchResponseData["statusCode"]>().toEqualTypeOf<number | undefined>();
expectTypeOf<FetchResponseData["finalUrl"]>().toEqualTypeOf<string | undefined>();
expectTypeOf<PageData["statusCode"]>().toEqualTypeOf<number | undefined>();
expectTypeOf<PageData["finalUrl"]>().toEqualTypeOf<string | undefined>();
});

test("includes public server region and status values", () => {
const region: SessionRegion = "us";
const status: SessionStatus = "close-error";
Expand Down