|
1 |
| -import { Locator, Page } from "@playwright/test"; |
| 1 | +import { Locator } from "@playwright/test"; |
2 | 2 | import { LogLine } from "../../types/log";
|
3 | 3 | import {
|
4 | 4 | PlaywrightCommandException,
|
@@ -495,110 +495,6 @@ export class StagehandActHandler {
|
495 | 495 | });
|
496 | 496 | }
|
497 | 497 |
|
498 |
| - private async handlePossiblePageNavigation( |
499 |
| - actionDescription: string, |
500 |
| - xpath: string, |
501 |
| - initialUrl: string, |
502 |
| - domSettleTimeoutMs: number, |
503 |
| - ): Promise<void> { |
504 |
| - // 1) Log that we’re about to check for page navigation |
505 |
| - this.logger({ |
506 |
| - category: "action", |
507 |
| - message: `${actionDescription}, checking for page navigation`, |
508 |
| - level: 1, |
509 |
| - auxiliary: { |
510 |
| - xpath: { |
511 |
| - value: xpath, |
512 |
| - type: "string", |
513 |
| - }, |
514 |
| - }, |
515 |
| - }); |
516 |
| - |
517 |
| - // 2) Race against a new page opening in a tab or timing out |
518 |
| - const newOpenedTab = await Promise.race([ |
519 |
| - new Promise<Page | null>((resolve) => { |
520 |
| - // TODO: This is a hack to get the new page. |
521 |
| - // We should find a better way to do this. |
522 |
| - this.stagehandPage.context.once("page", (page) => resolve(page)); |
523 |
| - setTimeout(() => resolve(null), 1_500); |
524 |
| - }), |
525 |
| - ]); |
526 |
| - |
527 |
| - // 3) Log whether a new tab was opened |
528 |
| - this.logger({ |
529 |
| - category: "action", |
530 |
| - message: `${actionDescription} complete`, |
531 |
| - level: 1, |
532 |
| - auxiliary: { |
533 |
| - newOpenedTab: { |
534 |
| - value: newOpenedTab ? "opened a new tab" : "no new tabs opened", |
535 |
| - type: "string", |
536 |
| - }, |
537 |
| - }, |
538 |
| - }); |
539 |
| - |
540 |
| - // 4) If new page opened in new tab, close the tab, then navigate our main page |
541 |
| - if (newOpenedTab) { |
542 |
| - this.logger({ |
543 |
| - category: "action", |
544 |
| - message: "new page detected (new tab) with URL", |
545 |
| - level: 1, |
546 |
| - auxiliary: { |
547 |
| - url: { |
548 |
| - value: newOpenedTab.url(), |
549 |
| - type: "string", |
550 |
| - }, |
551 |
| - }, |
552 |
| - }); |
553 |
| - await newOpenedTab.close(); |
554 |
| - await this.stagehandPage.page.goto(newOpenedTab.url()); |
555 |
| - await this.stagehandPage.page.waitForLoadState("domcontentloaded"); |
556 |
| - } |
557 |
| - |
558 |
| - // 5) Wait for the DOM to settle |
559 |
| - await this.stagehandPage |
560 |
| - ._waitForSettledDom(domSettleTimeoutMs) |
561 |
| - .catch((e) => { |
562 |
| - this.logger({ |
563 |
| - category: "action", |
564 |
| - message: "wait for settled DOM timeout hit", |
565 |
| - level: 1, |
566 |
| - auxiliary: { |
567 |
| - trace: { |
568 |
| - value: e.stack, |
569 |
| - type: "string", |
570 |
| - }, |
571 |
| - message: { |
572 |
| - value: e.message, |
573 |
| - type: "string", |
574 |
| - }, |
575 |
| - }, |
576 |
| - }); |
577 |
| - }); |
578 |
| - |
579 |
| - // 6) Log that we finished waiting for possible navigation |
580 |
| - this.logger({ |
581 |
| - category: "action", |
582 |
| - message: "finished waiting for (possible) page navigation", |
583 |
| - level: 1, |
584 |
| - }); |
585 |
| - |
586 |
| - // 7) If URL changed from initial, log the new URL |
587 |
| - if (this.stagehandPage.page.url() !== initialUrl) { |
588 |
| - this.logger({ |
589 |
| - category: "action", |
590 |
| - message: "new page detected with URL", |
591 |
| - level: 1, |
592 |
| - auxiliary: { |
593 |
| - url: { |
594 |
| - value: this.stagehandPage.page.url(), |
595 |
| - type: "string", |
596 |
| - }, |
597 |
| - }, |
598 |
| - }); |
599 |
| - } |
600 |
| - } |
601 |
| - |
602 | 498 | public async act({
|
603 | 499 | action,
|
604 | 500 | steps = "",
|
|
0 commit comments