Learning center

Reproduce a bug that needs two tabs

Some bugs only appear when a second tab of the same site is open: a cart that empties, a sign-out that does not stick, a form that saves stale data. The written steps describe one tab, so the maintainer never opens the second. Name both tabs in the report, and replay them in the same browser profile, because two separate profiles share nothing.

Why a second tab changes behavior#

Tabs of the same origin in one browser profile share state:

  • Cookies and local storage are shared across all tabs of the origin. Session storage is not: each tab has its own.
  • IndexedDB and Cache Storage are shared.
  • A service worker controls every tab of its scope.
  • Pages can talk directly with the storage event and BroadcastChannel.

The storage event fires in the other same-origin documents when one of them changes local storage, not in the document that made the change. We checked this in Chromium with three pages: two in one Playwright browser context and one in a separate context. When the first page wrote localStorage.setItem('cart', '1'), the second page in the same context received a storage event for cart. The writing page received none. The page in the separate context received nothing and could not read the value. MDN: storage event

Write down both tabs#

A two-tab report needs, for each tab: its URL, what you did in it, and the order of those actions across tabs. A small table is clearer than prose:

StepTab ATab B
1Open /cart, add item A-1
2Open /cart, shows A-1
3Remove A-1
4Click Checkout: order contains A-1

Say how long each tab had been open, and whether one was in the background. A background tab can miss timers and updates, and some apps only refresh on focus.

Replay both tabs in one context#

In Playwright, open two pages from the same browser context. They share cookies and storage, as two tabs in one profile do:

const context = await browser.newContext();
const tabA = await context.newPage();
const tabB = await context.newPage();
await tabA.goto('https://staging.example.test/cart');
await tabA.getByRole('button', { name: 'Add A-1' }).click();
await tabB.goto('https://staging.example.test/cart');
await tabB.getByRole('button', { name: 'Remove A-1' }).click();
await tabA.getByRole('button', { name: 'Checkout' }).click();
await expect(tabA.getByRole('heading', { name: 'Order placed' })).toBeVisible();
await expect(tabA.getByRole('list', { name: 'Order items' })).not.toContainText('A-1');

The last line is the test: the order must not contain the item removed in tab B.

Two calls to browser.newContext() are like two separate profiles, so they will not reproduce a shared-state bug. In Chrome by hand, use two tabs in the same window or profile. An incognito window and a normal window do not share storage.

Playwright: Pages ยท Playwright: Browser contexts

Worked example: an order with a removed item#

This example is fictional and matches the table above. A tester reports that an order included an item they had removed. Single-tab steps do not reproduce it.

The developer asks whether another tab was open, and the tester confirms the table's sequence. With two pages in one Playwright context, the order contains A-1 every time. The cart kept its items in memory in each tab and wrote local storage only on change, so tab B's removal updated storage, and tab A ignored the storage event. Checkout posted tab A's in-memory cart. The fix listened for the event and reloaded the cart from storage, and the two-page script became the regression test.

Questions#

What about two different browsers or devices?

They share nothing on the client, so a bug across devices goes through the server: two sessions editing the same record, or a server-side cart. Record both sessions' times and request IDs, and see linking browser evidence to server logs for that part.

Does this apply to sign-out?

Yes. Signing out in one tab clears a cookie or storage that the other tab may not notice until its next request. A report of "I was still signed in" often has a second tab that never reloaded.

Can a bug need two windows rather than two tabs?

Windows of one profile share state like tabs do. The difference that matters is usually focus and visibility: a second window can leave both pages visible, while a background tab is hidden.

Return to reproducing what someone else saw for the other layers a replay needs.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading