[Question] Are aborted requests able to set cookies?
See original GitHub issueI am using Playwright Python as part of my own SaaS product to inspect web pages. On the following URL a Youtube video is embedded, and the consent management software Usercentrics is in place to block loading the video until the user has given their consent:
Usercentrics aborts the network request to Youtube using some JS code. When loading this page in a “real” Chrome browser and watching the devtools network tab, the reqest is sometimes highlighted in red with the status “aborted”. The request does in no case set any cookies.
When loading the page with Playwright, one can detect that the request is aborted in 100% of all test runs (see the example code). However, in about 50% of the test runs I do, I can see multiple cookies from the domain youtube.com. There is no other request to Youtube, so apparently this aborted request manages to set cookies. How is this possible, this seems to me like a bug in Playwright? Wether cookies are set or not is a crucial result in my (data protection related) SaaS product.
import asyncio
from playwright.async_api import async_playwright
from random import randrange
async def main():
async with async_playwright() as p:
for browser_type in [p.chromium]:
browser = await browser_type.launch()
page = await browser.new_page()
page.on("requestfailed", lambda request: print("request failed",request.url,request.failure))
await page.goto(url='https://www.phoenix-mecano.ch/de/produkte/fahrerlose-transportsysteme-fts/fahrerlose-transportsysteme-fts.html/779',wait_until = 'networkidle')
cookies = await page.context.cookies()
for cookie in cookies:
print("cookie",cookie['name'],cookie['domain'])
await browser.close()
asyncio.get_event_loop().run_until_complete(main())
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Hey @dgozman , I was unable to produce a repro that reliably shows the effect. I presume this is some race conditions related thing going on. We might close this ticket because it is not repdoducible, in case I find a repro I will open a new ticket. Thanks so far!
@dgozman I fully understand - tried to make it reproducable with a trace but with no avail, even though the effect still persists when using a Chrome on my Macbook. I will keep trying to set up a repro and will follow up. Thanks!