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
5 changes: 5 additions & 0 deletions .changeset/petite-donuts-lead.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

support api usage for extract with no args
3 changes: 3 additions & 0 deletions lib/StagehandPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ export class StagehandPage {

// check if user called extract() with no arguments
if (!instructionOrOptions) {
if (this.api) {
return this.api.extract<T>({});
}
return this.extractHandler.extract();
}

Expand Down
6 changes: 6 additions & 0 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export class StagehandAPI {
async extract<T extends z.AnyZodObject>(
options: ExtractOptions<T>,
): Promise<ExtractResult<T>> {
if (!options.schema) {
return this.execute<ExtractResult<T>>({
method: "extract",
args: {},
});
}
const parsedSchema = zodToJsonSchema(options.schema);
return this.execute<ExtractResult<T>>({
method: "extract",
Expand Down
4 changes: 2 additions & 2 deletions types/stagehand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export interface ActResult {
}

export interface ExtractOptions<T extends z.AnyZodObject> {
instruction: string;
schema: T;
instruction?: string;
schema?: T;
modelName?: AvailableModel;
modelClientOptions?: ClientOptions;
domSettleTimeoutMs?: number;
Expand Down