Logo

dev-resources.site

for different kinds of informations.

Overcoming SameSite cookie issue in Cypress when running on Chrome or Edge

Published at
1/4/2021
Categories
cypress
chromium
samesite
401
Author
poponuts
Categories
4 categories in total
cypress
open
chromium
open
samesite
open
401
open
Author
8 person written this
poponuts
open
Overcoming SameSite cookie issue in Cypress when running on Chrome or Edge

New year ๐ŸŽ‰, new me ๐Ÿคช... or maybe not, coz my โค๏ธ for Cypress has not died off... Well, almost.

You see, I just changed company last December (yey!) and my first few days were spent on building a basic automation framework. Understandably, first thing I tried out is the UI login ๐Ÿ”‘ (Sorry, API does not have the wow factor when you're doing a demo)

So, I told myself, "I got this and let me work my magic!" but boy, was I so wrong! Manually doing it, obviously, it works fine. Using Cypress' default browser, Electron, it works great. Having fun yet so far! Here we go... using Chrome, NA-DA โŒ! I got an 401 Unauthorised access error!

I could have been very lazy and just told everyone that if it works with Electron, then it should be fine but no, I was determined to make it work with Chrome. It took me maybe a couple of days, munching snacks while my belly blew up, and a thousand times clicking Stackoverflow and Github Cypress issues looking for an answer but there was none ๐Ÿ™…! I had to look outside Cypress and more on generic Javascript and after multiple hair-twisting re-tries scraping the XHR requests, I found the holy grail ๐Ÿ™๐Ÿป

With me hoping that customer churn rate with Cypress does not further increase, here's how you should do it:
Under cypress/plugins/index.js, include the following condition:

module.exports = (on, config) => {
    on('before:browser:launch', (browser = {}, launchOptions) => {
        if (browser.name === 'chrome' || browser.name === 'edge') {
            launchOptions.args.push('--disable-features=SameSiteByDefaultCookies') // bypass 401 unauthorised access on chromium-based browsers
            return launchOptions
        }
    })
}
Enter fullscreen mode Exit fullscreen mode

With the above code, SameSite default cookie issues are by-passed when using Chromium-based browsers. This includes Edge so don't forget to include that browser in the condition.

Again, happy Cypress testing! ๐Ÿค—

chromium Article's
30 articles in total
Favicon
Avoiding a "Host Permission" Review Delay When Publishing a Chrome Extension
Favicon
Proyect Fugu
Favicon
Proyecto Fugu: Revolucionando las aplicaciones web progresivas (PWA)
Favicon
How To Download An Old Version of Chromium
Favicon
Why gRPC is not natively supported by Browsers
Favicon
Running Puppeteer in a Docker container on Raspberry Pi
Favicon
Chromium Spelunking: Connecting to Proxies
Favicon
๐ŸŒ Installing Chromium on Mac Apple M2 Pro (Tutorial)
Favicon
Chromium Spelunking: The IO Thread
Favicon
Chromium Spelunking: A Stuck Task
Favicon
Chromium Spelunking: Threads and Tasks
Favicon
Chromium Spelunking: Creating a Request
Favicon
Chromium Spelunking: Churl
Favicon
Chromium Spelunking: Life and Times
Favicon
Chromium Spelunking: Getting Started
Favicon
Google Chrome ใฎ CVE ่„†ๅผฑๆ€ง: 2022 ๅนด 12 ๆœˆ้ ƒใฎใƒชใƒชใƒผใ‚นใƒใƒผใ‚ธใƒงใƒณใพใง
Favicon
CVE vulnerabilities on Google Chrome prior to releases around on Dec. 2022
Favicon
Stop Chromium from asking about default browser
Favicon
Message loop
Favicon
Share highlight in Chrome/ Chromium
Favicon
Useful Visual Studio Code Extension for Developing Chromium
Favicon
Fix sameSite cookie issue in Cypress by installing an older version of Chromium
Favicon
Why HTTP streaming upload matters on Web browser
Favicon
Google refusing to connect to other sites?!
Favicon
Chromium console stopped working. - What's wrong? How do I fix it?
Favicon
Chrome Omnibox
Favicon
Using Chromium to replace Electron Applications
Favicon
Snapd doesn't work on WSL2 Ubuntu20.04
Favicon
Prevent chromedp Chromium zombie processes from stacking
Favicon
Overcoming SameSite cookie issue in Cypress when running on Chrome or Edge

Featured ones: