[BUG] Firefox tests crash with "Unexpected number of tabs in the new window"
Context:
- Playwright Version: 1.13.1
- Operating System: Windows
- Node.js version: v12.22.4
- Browser: Firefox
- Extra: N/A
Code Snippet
Help us help you! Put down a short code snippet that illustrates your bug and that we can run and debug locally. For example:
C:\dev>npx playwright ff google.com
[open: Protocol error (Browser.newPage): Unexpected number of tabs in the new window: 2 newPage@chrome://juggler/content/TargetRegistry.js:321:13
] {
name: 'Error'
}
Describe the bug
Trying to run tests, even just using the npx playwright ff google.com command as per above, crashes in Firefox immediately. When I run not in headless, I can see the extra Firefox privacy tab:

@gcatto interesting! Do you have any enterprise policies installed on your machine? I just ran the same thing and it works perfectly fine for me.
@aslushnikov ah yes, this is on an enterprise machine with enterprise policies and enterprise firefox. Just learning my way around Playwright so far, not yet clear to me how Playwright interacts with installed browsers and such.
@aslushnikov any further thoughts or guidance on this front? Not really sure where/how to start tackling it. Thanks!
~~I'm able to reproduce:~~
I had a broken installation.
@gcatto could you try if its still reproducible with npx playwright@next ff google.com?
@mxschmitt Just tried it out, and unfortunately got the same error:
C:\dev>npx playwright@next ff google.com
[open: Protocol error (Browser.newPage): Unexpected number of tabs in the new window: 2 newPage@chrome://juggler/content/TargetRegistry.js:322:13
] {
name: 'Error'
}
Hi all,
do you know any workaround for this please? Reproducible on my enterprise laptop, not on my private one: Playwright version: 1.16.0 (Java) `com.microsoft.playwright.PlaywrightException: Error { message='Protocol error (Browser.newPage): Unexpected number of tabs in the new window: 2 newPage@chrome://juggler/content/TargetRegistry.js:323:13
... }`
Best regards
Hi, I have the same issue on Windows.
Playwright Version: 1.16.3
browser.newPage: Protocol error (Browser.newPage): Unexpected number of tabs in the new window: 2 newPage@chrome://juggler/content/TargetRegistry.js:323:13
Is there any workaround?
Hi, I have the same issue on Windows.
Playwright Version: 1.16.3
browser.newPage: Protocol error (Browser.newPage): Unexpected number of tabs in the new window: 2 newPage@chrome://juggler/content/TargetRegistry.js:323:13Is there any workaround?
I solved by using 1.17.0-rc1 playwright version.
I see the same error with playwright 1.19.2.
$ npx playwright ff google.com
: Protocol error (Browser.newPage): Unexpected number of tabs in the new window: 2 newPage@chrome://juggler/content/TargetRegistry.js:324:13
at captureRawStack (C:\myproject\node_modules\@playwright\test\node_modules\playwright-core\lib\utils\stackTrace.js:64:17) {
name: 'Error'
}
Getting the same error msg for Nodejs as well as for Java binding.
Nodejs: [firefox] › example.spec.ts:247:3 › Counter › should display the current number of todo items
browserContext.newPage: Protocol error (Browser.newPage): Unexpected number of tabs in the new window: 2 newPage@chrome://juggler/content/TargetRegistry.js:324:13
Java Exception in thread "main" com.microsoft.playwright.PlaywrightException: Error { message='Protocol error (Browser.newPage): Unexpected number of tabs in the new window: 2 newPage@chrome://juggler/content/TargetRegistry.js:324:13
name='Error stack='Error: Protocol error (Browser.newPage): Unexpected number of tabs in the new window: 2 newPage@chrome://juggler/content/TargetRegistry.js:324:13
at C:\Users\RSALUN~1\AppData\Local\Temp\playwright-java-13735235671465553076\package\lib\server\firefox\ffConnection.js:92:16
at new Promise (<anonymous>)
at FFConnection.send (C:\Users\RSALUN~1\AppData\Local\Temp\playwright-java-13735235671465553076\package\lib\server\firefox\ffConnection.js:88:12)
at FFBrowserContext.newPageDelegate (C:\Users\RSALUN~1\AppData\Local\Temp\playwright-java-13735235671465553076\package\lib\server\firefox\ffBrowser.js:306:41)
at FFBrowserContext.newPage (C:\Users\RSALUN~1\AppData\Local\Temp\playwright-java-13735235671465553076\package\lib\server\browserContext.js:335:37)
at BrowserContextDispatcher.newPage (C:\Users\RSALUN~1\AppData\Local\Temp\playwright-java-13735235671465553076\package\lib\dispatchers\browserContextDispatcher.js:150:67)
at DispatcherConnection.dispatch (C:\Users\RSALUN~1\AppData\Local\Temp\playwright-java-13735235671465553076\package\lib\dispatchers\dispatcher.js:352:46)
} at com.microsoft.playwright.impl.WaitableResult.get(WaitableResult.java:54) at com.microsoft.playwright.impl.ChannelOwner.runUntil(ChannelOwner.java:103) at com.microsoft.playwright.impl.Connection.sendMessage(Connection.java:105) at com.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:94) at com.microsoft.playwright.impl.ChannelOwner.sendMessage(ChannelOwner.java:90) at com.microsoft.playwright.impl.BrowserContextImpl.newPageImpl(BrowserContextImpl.java:323) at com.microsoft.playwright.impl.BrowserContextImpl.lambda$newPage$12(BrowserContextImpl.java:316) at com.microsoft.playwright.impl.LoggingSupport.withLogging(LoggingSupport.java:47) at com.microsoft.playwright.impl.ChannelOwner.withLogging(ChannelOwner.java:79) at com.microsoft.playwright.impl.BrowserContextImpl.newPage(BrowserContextImpl.java:316) at com.microsoft.playwright.impl.BrowserContextImpl.newPage(BrowserContextImpl.java:44) at main.WebKitScreenshot.main(WebKitScreenshot.java:26) Caused by: com.microsoft.playwright.impl.DriverException: Error { message='Protocol error (Browser.newPage): Unexpected number of tabs in the new window: 2 newPage@chrome://juggler/content/TargetRegistry.js:324:13
name='Error
Hey folks,
Are you all experiencing this on Windows? Do you have a repro that we can debug?
It does feel like there are some custom preferences (policy) in Firefox that override ours. Could it be the case?
@aslushnikov - Yes on windows. Running any basic(Getting Started) example leads me to this error. However, if I downgrade the version to 1.17.0 - it doesn't throw any such error.
I think I've had this problem at every version since I started using Playwright with 1.13.1, although I don't think I've used every major and minor version.
This happens for me on Windows on a corporate machine with Firefox ESR. Unsure about a repro to debug besides that, because I don't have insight/access to all the corporate policies and the like.
I'd also like the chime in and say I'm running into the same issues using Firefox and Playwright version 1.20.1. All other browsers work
I am also able to reproduce this issue with playwright version 1.22.1 With previous versions, this issue was not reproducible, recently I updated to playwright version 1.22 and started facing this issue.
browserContext.newPage: Protocol error (Browser.newPage): Unexpected number of tabs in the new window: 2 newPage@chrome://juggler/content/TargetRegistry.js:324:13
at Object.page [as fn] (C:\{ProjectLocation}\node_modules\@playwright\test\lib\index.js:647:29)
at C:\{ProjectLocation}\node_modules\@playwright\test\lib\fixtures.js:98:81

Could you please try adding the browser.privacySegmentation.preferences.show preference?
const browser = await firefox.launch({
firefoxUserPrefs: {
'browser.privacySegmentation.preferences.show': false,
}
});
@aslushnikov With the setting you suggested I am getting the same error as before.
playwright:1.24.0
[Update] Also tested with playwright:1.30.0 and playwright:1.31.1
@aslushnikov Getting the same issues again with above settings with playwright 1.24.2
Looks like an feature of Firefox which playwright is unable to handle - https://support.mozilla.org/en-US/questions/1257360
I was having the same problem but I got it working again by deleting the firefox folder in the installation folder of the browsers or here C:/users/{user}/AppData/Local/ms-playwright and then installing again the browser.
"npx playwright install"
Using 1.30.0 on Ubuntu 22.04.1, I still get this error with
Playwright.create().firefox().launch(new BrowserType.LaunchOptions().setHeadless(false).setFirefoxUserPrefs(Map.of("browser.privacySegmentation.preferences.show", false))).newContext().newPage();
even after
rm -rf ~/.cache/ms-playwright/firefox-1372
First a popup is shown
Failed to read the configuration file. Please contact your system administrator.
Hello ! I had the same issue today with Playwright 1.30.0, it seems fixed in 1.31.0
Hmm, I see 1.31.1 on https://mcr.microsoft.com/en-us/product/playwright/tags (curiously skopeo list-tags docker://mcr.microsoft.com/playwright/java does not show anything newer than 1.30.0), but for Java https://repo1.maven.org/maven2/com/microsoft/playwright/playwright/ seems stuck on 1.30.0.
A new version of Java gets released soon!
@adasilva-gran I still get the same error with playwright 1.31.1.
Any update on this this is an issue of the privacy tab auto opening is there a workaround?
One year later, I still get this error. I am currently on playwright 1.41.2 which comes with Firefox 121 (v1438).
What i noticed is playwright does not create a Firefox profile in the temp folder (it does with chromium, though).
Here is part of the log using DEBUG=pw:browser:
pw:browser <launching> C:\Users\bob\AppData\Local\ms-playwright\firefox-1438\firefox\firefox.exe -no-remote -headless -profile C:\Users\bob\AppData\Local\Temp\playwright_firefoxdev_profile-U9Nr3R -juggler-pipe -silent +0ms
pw:browser <launched> pid=8644 +148ms
pw:browser [pid=8644][err] *** You are running in headless mode. +287ms
pw:browser [pid=8644][out] console.error: ({}) +673ms
pw:browser [pid=8644][out] +6ms
pw:browser [pid=8644][out] Juggler listening to the pipe +0ms
pw:browser [pid=8644][out] Crash Annotation GraphicsCriticalError: |[0][GFX1-]: RenderCompositorSWGL failed mapping default framebuffer, no dt (t=13.9334) [GFX1-]: RenderCompositor
SWGL failed mapping default framebuffer, no dt +472ms
pw:browser [pid=8644][err] JavaScript error: resource://gre/modules/XULStore.sys.mjs, line 60: Error: Can't find profile directory. +367ms
Now, when I run this firefox.exe command manually in a terminal, I get the playwright_firefoxdev_profile-U9Nr3R in the temp folder, but only if I remove the -juggler-pipe parameter.
--pref='datareporting.policy.firstRunURL=""' can fix it
source: Firefox loads privacy info page
@gcatto
--pref='datareporting.policy.firstRunURL=""'can fix it source: Firefox loads privacy info page @gcatto
Good tip, thank you!