@@ -31,6 +31,7 @@ export class EventCapture {
3131 private pendingActions : Action [ ] = [ ] ;
3232 private inputTracking = new Map < string , string > ( ) ;
3333 private lastUrl = "" ;
34+ private lastInteractionTime = 0 ;
3435
3536 constructor ( page : Page ) {
3637 this . page = page ;
@@ -61,10 +62,22 @@ export class EventCapture {
6162 if ( frame === this . page . mainFrame ( ) ) {
6263 const newUrl = this . page . url ( ) ;
6364 if ( newUrl !== this . lastUrl ) {
64- this . pendingActions . push ( {
65- type : "navigate" ,
66- url : newUrl ,
67- } ) ;
65+ // Check if navigation occurred within 1 second of last interaction
66+ const timeSinceInteraction = Date . now ( ) - this . lastInteractionTime ;
67+
68+ if ( timeSinceInteraction <= 1000 ) {
69+ // Automatic redirect (likely caused by previous action)
70+ this . pendingActions . push ( {
71+ type : "waitForNavigation" ,
72+ } ) ;
73+ } else {
74+ // Manual navigation
75+ this . pendingActions . push ( {
76+ type : "navigate" ,
77+ url : newUrl ,
78+ } ) ;
79+ }
80+
6881 this . lastUrl = newUrl ;
6982
7083 // Re-inject listeners after navigation
@@ -89,6 +102,7 @@ export class EventCapture {
89102 switch ( event . type ) {
90103 case "click" :
91104 if ( event . selector ) {
105+ this . lastInteractionTime = Date . now ( ) ;
92106 this . pendingActions . push ( {
93107 type : "click" ,
94108 selector : event . selector ,
@@ -105,6 +119,7 @@ export class EventCapture {
105119
106120 case "change" :
107121 if ( event . selector ) {
122+ this . lastInteractionTime = Date . now ( ) ;
108123 if ( event . inputType === "select" && event . value !== undefined ) {
109124 this . pendingActions . push ( {
110125 type : "select" ,
0 commit comments