🎯 What You Will Learn
Open, list, select, and close tabs while keeping page references and workflow state predictable.
- Create and identify browser tabs
- Switch tabs without reusing stale references
- Coordinate a two-page research workflow
- Close tabs and sessions cleanly
Treat Every Tab as a Separate Page
Each tab has its own URL, DOM, history, and refs. A session can own several tabs, but only one is active for CLI actions at a time.
| Command | Effect |
|---|---|
| tab-new [url] | Create a new page and optionally navigate it |
| tab-list | Show tab indexes and URLs |
| tab-select <index> | Make one page active |
| tab-close [index] | Close the active or specified page |
Open the Primary Tab
Start the session on the source page and inspect it before creating more tabs.
"$PWCLI" -s=research open https://playwright.dev --headed
"$PWCLI" -s=research snapshot
"$PWCLI" -s=research tab-listCreate a Second Tab
Open the locator documentation in another tab, then list tabs so you know the assigned index.
"$PWCLI" -s=research tab-new https://playwright.dev/docs/locators
"$PWCLI" -s=research tab-listSelect and Snapshot
Tab selection changes the active Page. Always snapshot after selection before using any ref.
"$PWCLI" -s=research tab-select 1
"$PWCLI" -s=research snapshot
"$PWCLI" -s=research find "Locate by role"Move Between Tabs Deliberately
List before selecting when a popup may have changed tab order. Treat the returned index as current session state rather than a permanent value.
"$PWCLI" -s=research tab-list
"$PWCLI" -s=research tab-select 0
"$PWCLI" -s=research snapshotHandle a Tab Created by the Page
A click may open a popup instead of navigating the active page. Compare tab-list output before and after the click to find the new tab.
- List tabs and note the indexes.
- Snapshot and click the popup-producing link.
- List tabs again.
- Select the new index and snapshot it.
Avoid Cross-tab References
References are meaningful only for the page snapshot that produced them. Switching back to a tab does not make a ref from another page valid.
Cross-tab bug: If a command reports a missing target after a tab switch, snapshot the active tab instead of trying random refs.
Close Tabs and the Session
Close temporary tabs when the workflow finishes, verify the remaining list, then close the browser session.
"$PWCLI" -s=research tab-close 1
"$PWCLI" -s=research tab-list
"$PWCLI" -s=research closeRecap
- Every tab is a separate Page.
- List tabs before relying on an index.
- Select, snapshot, then interact.
- Never carry element refs across tabs.
Checkpoint: You have completed the workflow and have a repeatable reference for your next Playwright project.