Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I would like to run my PlayWright Java script in Chrome Incognito browser ... But it is not running in Incognito mode #31512

Open
kiranbandaqa opened this issue Jul 2, 2024 · 7 comments

Comments

@kiranbandaqa
Copy link

kiranbandaqa commented Jul 2, 2024

if (browserName.equalsIgnoreCase("Chrome")) {
page = getBrowser(playwright, browserName)
.launch(new BrowserType.LaunchOptions()
.setHeadless(false)
.setChannel("chrome")
.setArgs(List.of("--start-maximized", "--incognito")))
.newContext(new Browser.NewContextOptions().setViewportSize(null))
.newPage();

    }   This is my code snippet 
@mxschmitt
Copy link
Member

You don't need to specify the args. Each BrowserContext is isolated. It might not look like an incognito tab, but they are isolated. In the web there is no notion of an incognito tab, so the web-page you are testing, can't tell the difference.

Does this help?

@0x34353534
Copy link

0x34353534 commented Jul 5, 2024

@mxschmitt and @kiranbandaqa, I am also seeing that Chromium in Playwright is not truly incognito.

When I launch my application in a Playwright test, with no cookies/origins set, I am presented with "Continue as User X". It recognizes me.

Test cases to confirm this behavior is because Playwrights version of Chromium "isolated" is not the same as Chromium incognito.

  • Open application in Chromium using Playwright: I see "Continue as User X" and can continue with SSO.
  • Open application in Chromium using Playwright with launchOptions.args including --incognito: I see "Continue as User X" and can continue with SSO.
  • Open application in Chromium locally (No Playwright): I see "Continue as User X" and can continue with SSO.
  • Open application in Chromium with flag --incognito: The browser has no idea who I am - I am force to provide credentials.
  • Open application in Chromium using Playwright in GitHub workflow runner: The browser has no idea who I am - I am force to provide credentials.

While it runs as I would expect on the CI server, it should mirror my local runs. Especially if the browsers are truly isolated here.

Its clear the issue lies in the fact some local credentials cache is being picked up when Chromium is not truly run in incognito mode, but I am at a loss as to how to prevent it from happening.

Any ideas as to what might be wrong here, or guidance on getting parity between local Chromium --incognito and Playwrights version of browser isolation?

@mxschmitt
Copy link
Member

@0x533435353447 where do you see "Continue as User X"? Could you provide us more details / screenshot? This would help us to reason about where this is coming from. From a website standpoint, in e.g. JavaScript, storage, like cookies etc. we are fully isolated - this is one of Playwrights core capabilities.

(There is a known issue about AAD auth - maybe you are encountering this)

@0x34353534
Copy link

Thanks @mxschmitt, the "Continue as User X" appears on one of our authentication/login systems that protects the application under test. Where X is the name of the user it has detected. So, http://my-applications redirects to https://login-application (Where "Continue as User X" appears). The user alternatively redirected to an http://sso-application if a user is not detected which is actually what I would expect in all cases.

But on my local machine, X is always me, unless I spin up a local incognito browser outside of Playwright.

(There is a known issue about AAD auth - maybe you are encountering this)

We are not using AAD in this case. The authentication system is internal.

From a website standpoint, in e.g. JavaScript, storage, like cookies etc. we are fully isolated - this is one of Playwrights core capabilities.

I've debugged the test, and peeked into cookies/storage and I'm not seeing anything.

Is there a reason why Chromium does not appear to be in incognito mode when Playwright tests run? e.g. I would expect to see the Incognito badge in the browser menu bar as below.

chrome_WZ388MWYVh

Passing launchOptions.args of --incognito makes no difference (Despite it make a huge difference locally in terms of test reproducibility).

@mxschmitt
Copy link
Member

But on my local machine, X is always me, unless I spin up a local incognito browser outside of Playwright.

Would love to learn more about this! So any screenshots / more details what this auth uses under the hood are appreciated.

Is there a reason why Chromium does not appear to be in incognito mode when Playwright tests run? e.g. I would expect to see the Incognito badge in the browser menu bar as below.

Chromium recently changed the UI a bit, while it doesn't look like Incognito anymore, it is still incognito, see this lengthy discussion if you are curious. In a nutshell: nothing has changed the past few releases on a technicial perspective, only the Chromium UI doesn't make it look like incognito anymore.

@0x34353534
Copy link

I'll try gather some more details on the flow of events and report back.

@0x34353534
Copy link

@mxschmitt, after some further digging based on the link you sent, I've realized my problem is best described by #13954.

I am in fact using an AAD enrolled machine and that was the culprit behind the login screen knowing more about me than expected!

My solution per the linked issue was to pass in --auth-server-allowlist="_" to the launchOptions.args configuration, and set some empty httpCredentials under contextOptions. All from playwright.config.ts.

Is there a reason why --auth-server-allowlist="_" is not passed in as a default launch parameter to further the isolation? Without it, one can expect see different result running tests on a CI server if they scripted the tests to interact with a login page differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants