saml2aws icon indicating copy to clipboard operation
saml2aws copied to clipboard

Non-incognito browser session

Open project-administrator opened this issue 3 years ago • 4 comments

By default, saml2aws opens an incognito browser session. It would be great to specify the browser provider options to run the non-incognito session to retain cookies between the browser runs. I could create a PR with these changes, but I have not found the corresponding playwright browser launch options https://github.com/Versent/saml2aws/blob/master/pkg/provider/browser/browser.go#L32

Is the browser provider session opened as incognito on purpose, or is it the default setting of playwright package? ...

project-administrator avatar Mar 07 '23 07:03 project-administrator

Found the way around this issue by using the Chrome browser + this extension (source) instead of the saml2aws.

project-administrator avatar Sep 29 '23 08:09 project-administrator

I was messing around with the code a bit locally.

and found if you swap this:

launchOptions := playwright.BrowserTypeLaunchOptions{
	Headless: playwright.Bool(cl.Headless),
}

to

launchOptions := playwright.BrowserTypeLaunchPersistentContextOptions{
	Headless: playwright.Bool(cl.Headless),
}

and this

browser, err := browserType.Launch(launchOptions)

to

browser, err := browserType.LaunchPersistentContext("~/Library/Application Support/Google/Chrome/Default", launchOptions)

it will open chrome in a non incognito browser session, but doesnt load in your chrome profile. That should at least be a start for someone to pickup and work on this.

Note: ~/Library/Application Support/Google/Chrome/Default is the chrome data dir on chrome for mac

bsamsom avatar Feb 16 '24 14:02 bsamsom

both

launchOptions := playwright.BrowserTypeLaunchOptions{
	Headless: playwright.Bool(cl.Headless),
}

and

launchOptions := playwright.BrowserTypeLaunchPersistentContextOptions{
	Headless: playwright.Bool(cl.Headless),
}

let you pass in chrome args: https://peter.sh/experiments/chromium-command-line-switches/

launchOptions := playwright.BrowserTypeLaunchPersistentContextOptions{
	Headless: playwright.Bool(cl.Headless),
	Args:     []string{"--profile-directory=Profile 2"},
}

i tried passing in a bunch of options but couldnt get it to work as you would expect in a Non-incognito browser session

bsamsom avatar Feb 16 '24 15:02 bsamsom

My PR solves the issue: https://github.com/Versent/saml2aws/pull/1267

It still uses the private browsing window, but after first login your storageState (cookies/session-data) is re-used. I found this more reliable than trying to use playwright.BrowserTypeLaunchPersistentContextOptions

timharris777 avatar May 13 '24 18:05 timharris777