@@ -6,7 +6,6 @@ import { Page, defaultExtractSchema } from "../types/page";
6
6
import {
7
7
ExtractOptions ,
8
8
ExtractResult ,
9
- HistoryEntry ,
10
9
ObserveOptions ,
11
10
ObserveResult ,
12
11
} from "../types/stagehand" ;
@@ -46,11 +45,6 @@ export class StagehandPage {
46
45
private userProvidedInstructions ?: string ;
47
46
private waitForCaptchaSolves : boolean ;
48
47
private initialized : boolean = false ;
49
- private _history : Array < HistoryEntry > = [ ] ;
50
-
51
- public get history ( ) : ReadonlyArray < HistoryEntry > {
52
- return Object . freeze ( [ ...this . _history ] ) ;
53
- }
54
48
55
49
constructor (
56
50
page : PlaywrightPage ,
@@ -338,13 +332,15 @@ ${scriptContent} \
338
332
339
333
// Handle goto specially
340
334
if ( prop === "goto" ) {
335
+ const rawGoto : typeof target . goto =
336
+ Object . getPrototypeOf ( target ) . goto . bind ( target ) ;
341
337
return async ( url : string , options : GotoOptions ) => {
342
338
this . intContext . setActivePage ( this ) ;
343
339
const result = this . api
344
340
? await this . api . goto ( url , options )
345
- : await target . goto ( url , options ) ;
341
+ : await rawGoto ( url , options ) ;
346
342
347
- this . addToHistory ( "navigate" , { url, options } , result ) ;
343
+ this . stagehand . addToHistory ( "navigate" , { url, options } , result ) ;
348
344
349
345
if ( this . waitForCaptchaSolves ) {
350
346
try {
@@ -498,24 +494,6 @@ ${scriptContent} \
498
494
}
499
495
}
500
496
501
- public addToHistory (
502
- method : HistoryEntry [ "method" ] ,
503
- parameters :
504
- | ActOptions
505
- | ExtractOptions < z . AnyZodObject >
506
- | ObserveOptions
507
- | { url : string ; options : GotoOptions }
508
- | string ,
509
- result ?: unknown ,
510
- ) : void {
511
- this . _history . push ( {
512
- method,
513
- parameters,
514
- result : result ?? null ,
515
- timestamp : new Date ( ) . toISOString ( ) ,
516
- } ) ;
517
- }
518
-
519
497
async act (
520
498
actionOrOptions : string | ActOptions | ObserveResult ,
521
499
) : Promise < ActResult > {
@@ -536,7 +514,7 @@ ${scriptContent} \
536
514
if ( this . api ) {
537
515
const result = await this . api . act ( observeResult ) ;
538
516
await this . _refreshPageFromAPI ( ) ;
539
- this . addToHistory ( "act" , observeResult , result ) ;
517
+ this . stagehand . addToHistory ( "act" , observeResult , result ) ;
540
518
return result ;
541
519
}
542
520
@@ -568,7 +546,7 @@ ${scriptContent} \
568
546
if ( this . api ) {
569
547
const result = await this . api . act ( actionOrOptions ) ;
570
548
await this . _refreshPageFromAPI ( ) ;
571
- this . addToHistory ( "act" , actionOrOptions , result ) ;
549
+ this . stagehand . addToHistory ( "act" , actionOrOptions , result ) ;
572
550
return result ;
573
551
}
574
552
@@ -603,8 +581,7 @@ ${scriptContent} \
603
581
llmClient ,
604
582
requestId ,
605
583
) ;
606
-
607
- this . addToHistory ( "act" , actionOrOptions , result ) ;
584
+ this . stagehand . addToHistory ( "act" , actionOrOptions , result ) ;
608
585
return result ;
609
586
} catch ( err : unknown ) {
610
587
if ( err instanceof StagehandError || err instanceof StagehandAPIError ) {
@@ -632,7 +609,7 @@ ${scriptContent} \
632
609
} else {
633
610
result = await this . extractHandler . extract ( ) ;
634
611
}
635
- this . addToHistory ( "extract" , instructionOrOptions , result ) ;
612
+ this . stagehand . addToHistory ( "extract" , instructionOrOptions , result ) ;
636
613
return result ;
637
614
}
638
615
@@ -656,7 +633,7 @@ ${scriptContent} \
656
633
657
634
if ( this . api ) {
658
635
const result = await this . api . extract < T > ( options ) ;
659
- this . addToHistory ( "extract" , instructionOrOptions , result ) ;
636
+ this . stagehand . addToHistory ( "extract" , instructionOrOptions , result ) ;
660
637
return result ;
661
638
}
662
639
@@ -719,7 +696,7 @@ ${scriptContent} \
719
696
throw e ;
720
697
} ) ;
721
698
722
- this . addToHistory ( "extract" , instructionOrOptions , result ) ;
699
+ this . stagehand . addToHistory ( "extract" , instructionOrOptions , result ) ;
723
700
724
701
return result ;
725
702
} catch ( err : unknown ) {
@@ -757,7 +734,7 @@ ${scriptContent} \
757
734
758
735
if ( this . api ) {
759
736
const result = await this . api . observe ( options ) ;
760
- this . addToHistory ( "observe" , instructionOrOptions , result ) ;
737
+ this . stagehand . addToHistory ( "observe" , instructionOrOptions , result ) ;
761
738
return result ;
762
739
}
763
740
@@ -834,7 +811,7 @@ ${scriptContent} \
834
811
throw e ;
835
812
} ) ;
836
813
837
- this . addToHistory ( "observe" , instructionOrOptions , result ) ;
814
+ this . stagehand . addToHistory ( "observe" , instructionOrOptions , result ) ;
838
815
839
816
return result ;
840
817
} catch ( err : unknown ) {
0 commit comments