Skip to content

Commit b783d86

Browse files
authored
Merge pull request #1 from impulse-studio/cursor/investigate-and-plan-cookie-disappearance-bug-d0bb
2 parents a5a6044 + 6d251a5 commit b783d86

File tree

6 files changed

+42
-4
lines changed

6 files changed

+42
-4
lines changed

src/cli/callbacks/ci-mode/handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ function formatAction(action: Action): string {
1919
return `${action.type} ${chalk.gray(action.selector)}`;
2020
case "navigate":
2121
return `navigate ${chalk.gray(action.url)}`;
22+
case "waitForNavigation":
23+
return `wait for navigation`;
2224
case "screenshot":
2325
return `screenshot ${chalk.gray(action.name)}`;
2426
default: {

src/cli/callbacks/existing-story/handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function formatAction(action: Action): string {
1818
return `${action.type} ${chalk.gray(action.selector)}`;
1919
case "navigate":
2020
return `navigate ${chalk.gray(action.url)}`;
21+
case "waitForNavigation":
22+
return `wait for navigation`;
2123
case "screenshot":
2224
return `screenshot ${chalk.gray(action.name)}`;
2325
default: {

src/cli/callbacks/run-multiple-stories/handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function formatAction(action: Action): string {
1818
return `${action.type} ${chalk.gray(action.selector)}`;
1919
case "navigate":
2020
return `navigate ${chalk.gray(action.url)}`;
21+
case "waitForNavigation":
22+
return `wait for navigation`;
2123
case "screenshot":
2224
return `screenshot ${chalk.gray(action.name)}`;
2325
default: {

src/core/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ export interface NavigateAction extends BaseAction {
4646
url: string;
4747
}
4848

49+
export interface WaitForNavigationAction extends BaseAction {
50+
type: "waitForNavigation";
51+
}
52+
4953
export interface ScreenshotAction extends BaseAction {
5054
type: "screenshot";
5155
name: string;
@@ -57,6 +61,7 @@ export type Action =
5761
| SelectAction
5862
| CheckAction
5963
| NavigateAction
64+
| WaitForNavigationAction
6065
| ScreenshotAction;
6166

6267
export interface Story {

src/recorder/event-capture.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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",

src/runner/action-executor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ export async function executeAction(page: Page, action: Action): Promise<void> {
113113
break;
114114
}
115115

116+
case "waitForNavigation": {
117+
// Wait for navigation that was triggered by a previous action
118+
// This is used for automatic redirects (e.g., post-login redirects)
119+
// The previous action (click/input) already triggered the navigation
120+
// We just need to wait for it to complete to preserve cookies
121+
await page.waitForNavigation({
122+
waitUntil: "networkidle2",
123+
timeout: DEFAULT_TIMEOUT,
124+
});
125+
break;
126+
}
127+
116128
case "screenshot": {
117129
// Screenshot actions are handled externally by the runner
118130
// This should not be called directly through executeAction

0 commit comments

Comments
 (0)