microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.36k stars 3.63k forks source link

[BUG] goto() never returns #27165

Closed db-do closed 1 year ago

db-do commented 1 year ago

System info

The below stack trace is displayed in our logs and the Thread that is running this never returns from response = self.page.goto(link.url, timeout=NAVIGATE_TIMEOUT_SECS*1000, wait_until=WAIT_UNTIL)

After crawling approximately 300 pages we receive this error. It will always happen on the same site, but on random pages (around the 300th page). We believe that the site owner is intentionally returning bad info which causes this stack trace.

Since the code gets stuck, we cannot see what "cookies" are causing it or prevent it from getting stuck.


Problematic Code


NAVIGATE_TIMEOUT_SECS = 120
WAIT_UNTIL = 'load'
response = self.page.goto(link.url, timeout=NAVIGATE_TIMEOUT_SECS*1000, wait_until=WAIT_UNTIL)

Log snippet


[DEBUG]|2023-09-06 11:49:00,416|common.playutil|64f8c59688daff0a9d514f9f|filter_response: fetching http://redactedsitedyavc6szj6ppbplfqoz3pgrk3zw57my4vybgblpfeayd.onion/Thread-Equifax-data-breach node:internal/process/promises:288 triggerUncaughtException(err, true / fromPromise /); ^

ProtocolError: Protocol error (Storage.setCookies): Invalid cookie fields at /Users/me/projects/proj/venv/lib/python3.8/site-packages/playwright/driver/package/lib/server/chromium/crConnection.js:169:16 at new Promise () at CRSession.send (/Users/me/projects/proj/venv/lib/python3.8/site-packages/playwright/driver/package/lib/server/chromium/crConnection.js:165:12) at CRBrowserContext.addCookies (/Users/me/projects/proj/venv/lib/python3.8/site-packages/playwright/driver/package/lib/server/chromium/crBrowser.js:367:34) at BrowserContextAPIRequestContext._addCookies (/Users/me/projects/proj/venv/lib/python3.8/site-packages/playwright/driver/package/lib/server/fetch.js:400:25) at ClientRequest. (/Users/me/projects/proj/venv/lib/python3.8/site-packages/playwright/driver/package/lib/server/fetch.js:213:40) at Object.onceWrapper (node:events:629:26) at ClientRequest.emit (node:events:514:28) at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:700:27) at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17) { sessionClosed: false }

Node.js v18.17.0


Thread Dump


Thread 0x0000000174617000 (most recent call first): File "/Users/me/projects/proj/venv/lib/python3.8/site-packages/playwright/_impl/_sync_base.py", line 107 in _sync File "/Users/me/projects/proj/venv/lib/python3.8/site-packages/playwright/sync_api/_generated.py", line 9303 in goto File "/Users/me/projects/proj/src/crawling.py", line 400 in _goto File "/Users/me/projects/proj/src/crawling.py", line 377 in goto_with_retry File "/Users/me/projects/proj/src/crawling.py", line 327 in start_crawl_loop File "/Users/me/projects/proj/src/crawling.py", line 142 in _run File "/Users/me/projects/proj/src/crawling.py", line 119 in run File "/Users/me/.pyenv/versions/3.8.10/lib/python3.8/threading.py", line 932 in _bootstrap_inner File "/Users/me/.pyenv/versions/3.8.10/lib/python3.8/threading.py", line 890 in _bootstrap

Source code

Link to the GitHub repository with the repro

[https://github.com/your_profile/playwright_issue_title]

or

Test file (self-contained)

from playwright.sync_api import sync_playwright
with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    # ...
    browser.close()

Steps

Expected

1) Make sure that if this happens the error percolates out. AND/OR 2) Make sure this problem correctly returns or raises a catchable error. OR 3) Honors the timeout.

Actual

Nothing. The code never returns.

mxschmitt commented 1 year ago

This sounds like a bug! Sorry to hear. Do you have page.route by any chance in place?

You can debug which header this causes by setting the DEBUG=pw:api env var, this will then produce something like that, where you can share your set-cookie header with us so we can fix it.

 pw:api → GET http://localhost:8907/setcookie.html +6ms
  pw:api   user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/117.0.5938.48 Safari/537.36 +0ms
  pw:api   accept: */* +0ms
  pw:api   accept-encoding: gzip,deflate,br +0ms
  pw:api ← 200 OK +5ms
  pw:api   set-cookie: session=value,foo=bar; max-age=3600 +1ms
  pw:api   date: Sat, 09 Sep 2023 20:07:39 GMT +0ms
  pw:api   connection: close +0ms
  pw:api   content-length: 0 +0ms
db-do commented 1 year ago
GET http://zredactedz6kdyavc6szj6ppbplfqoz3pgrk3zw57my4vybgblpfeayd.onion/Thread-ProtonMail-and-Data-Anonymity
2023-09-11T18:12:06.041Z pw:api   user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
2023-09-11T18:12:06.041Z pw:api   accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
2023-09-11T18:12:06.041Z pw:api   accept-encoding: gzip,deflate,br
2023-09-11T18:12:06.041Z pw:api   cookie: mybb[announcements]=0; mybb[forumread]=a%3A1%3A%7Bi%3A17%3Bi%3A1694455236%3B%7D; mybb[threadread]=a%3A141%3A%7Bi%3A69504%3Bi%3A1694455161%3Bi%3A79395%3Bi%3A1694455098%3Bi%3A67509%3Bi%3A1694455117%3Bi%3A71401%3Bi%3A1694455166%3Bi%3A79667%3Bi%3A1694455120%3Bi%3A71243%3Bi%3A1694455158%3Bi%3A77189%3Bi%3A1694455199%3Bi%3A73492%3Bi%3A1694455149%3Bi%3A79658%3Bi%3A1694455146%3Bi%3A79957%3Bi%3A1694455172%3Bi%3A74174%3Bi%3A1694455195%3Bi%3A77377%3Bi%3A1694455233%3Bi%3A76139%3Bi%3A1694455230%3Bi%3A79397%3Bi%3A1694455192%3Bi%3A80165%3Bi%3A1694455202%3Bi%3A80221%3Bi%3A1694455206%3Bi%3A79399%3Bi%3A1694455209%3Bi%3A76257%3Bi%3A1694455221%3Bi%3A72415%3Bi%3A1694455218%3Bi%3A71137%3Bi%3A1694455236%3Bi%3A79154%3Bi%3A1694455329%3Bi%3A79081%3Bi%3A1694455248%3Bi%3A78435%3Bi%3A1694455273%3Bi%3A68659%3Bi%3A1694455349%3Bi%3A80299%3Bi%3A1694455261%3Bi%3A76298%3Bi%3A1694455352%3Bi%3A80295%3Bi%3A1694455267%3Bi%3A74818%3Bi%3A1694455284%3Bi%3A77201%3Bi%3A1694455343%3Bi%3A70063%3Bi%3A1694455337%3Bi%3A78562%3Bi%3A1694455364%3Bi%3A68787%3Bi%3A1694455312%3Bi%3A80298%3Bi%3A1694455320%3Bi%3A77566%3Bi%3A1694455340%3Bi%3A80311%3Bi%3A1694455346%3Bi%3A79932%3Bi%3A1694455355%3Bi%3A80120%3Bi%3A1694455358%3Bi%3A79660%3Bi%3A1694455361%3Bi%3A80241%3Bi%3A1694455367%3Bi%3A76677%3Bi%3A1694455370%3Bi%3A80156%3Bi%3A1694455373%3Bi%3A67654%3Bi%3A1694455376%3Bi%3A80218%3Bi%3A1694455379%3Bi%3A80213%3Bi%3A1694455382%3Bi%3A80164%3Bi%3A1694455455%3Bi%3A76990%3Bi%3A1694455396%3Bi%3A80068%3Bi%3A1694455404%3Bi%3A80229%3Bi%3A1694455410%3Bi%3A69756%3Bi%3A1694455440%3Bi%3A76166%3Bi%3A1694455419%3Bi%3A79888%3Bi%3A1694455429%3Bi%3A69679%3Bi%3A1694455458%3Bi%3A67682%3Bi%3A1694455473%3Bi%3A78099%3Bi%3A1694455443%3Bi%3A80070%3Bi%3A1694455447%3Bi%3A69997%3Bi%3A1694455461%3Bi%3A76672%3Bi%3A1694455467%3Bi%3A76665%3Bi%3A1694455470%3Bi%3A21347%3Bi%3A1694455479%3Bi%3A10941%3Bi%3A1694455481%3Bi%3A1149%3Bi%3A1694455531%3Bi%3A772%3Bi%3A1694455578%3Bi%3A99%3Bi%3A1694455510%3Bi%3A17603%3Bi%3A1694455540%3Bi%3A84%3Bi%3A1694455556%3Bi%3A14592%3Bi%3A1694455559%3Bi%3A389%3Bi%3A1694455518%3Bi%3A37%3Bi%3A1694455534%3Bi%3A1709%3Bi%3A1694455522%3Bi%3A6025%3Bi%3A1694455515%3Bi%3A2092%3Bi%3A1694455575%3Bi%3A333%3Bi%3A1694455547%3Bi%3A502%3Bi%3A1694455572%3Bi%3A427%3Bi%3A1694455553%3Bi%3A11463%3Bi%3A1694455565%3Bi%3A1031%3Bi%3A1694455562%3Bi%3A9830%3Bi%3A1694455569%3Bi%3A538%3Bi%3A1694455680%3Bi%3A326%3Bi%3A1694455601%3Bi%3A681%3Bi%3A1694455604%3Bi%3A445%3Bi%3A1694455648%3Bi%3A1368%3Bi%3A1694455669%3Bi%3A860%3Bi%3A1694455595%3Bi%3A522%3Bi%3A1694455651%3Bi%3A11193%3Bi%3A1694455627%3Bi%3A21062%3Bi%3A1694455671%3Bi%3A603%3Bi%3A1694455618%3Bi%3A77358%3Bi%3A1694455624%3Bi%3A2706%3Bi%3A1694455633%3Bi%3A336%3Bi%3A1694455639%3Bi%3A21194%3Bi%3A1694455657%3Bi%3A168%3Bi%3A1694455666%3Bi%3A24561%3Bi%3A1694455645%3Bi%3A3879%3Bi%3A1694455654%3Bi%3A91%3Bi%3A1694455663%3Bi%3A11283%3Bi%3A1694455675%3Bi%3A29812%3Bi%3A1694455683%3Bi%3A80030%3Bi%3A1694455687%3Bi%3A80035%3Bi%3A1694455691%3Bi%3A75787%3Bi%3A1694455697%3Bi%3A80233%3Bi%3A1694455700%3Bi%3A79930%3Bi%3A1694455703%3Bi%3A80173%3Bi%3A1694455706%3Bi%3A79879%3Bi%3A1694455709%3Bi%3A80268%3Bi%3A1694455714%3Bi%3A79859%3Bi%3A1694455717%3Bi%3A80232%3Bi%3A1694455720%3Bi%3A79878%3Bi%3A1694455724%3Bi%3A80262%3Bi%3A1694455733%3Bi%3A80110%3Bi%3A1694455738%3Bi%3A79434%3Bi%3A1694455742%3Bi%3A80239%3Bi%3A1694455748%3Bi%3A80235%3Bi%3A1694455751%3Bi%3A80270%3Bi%3A1694455754%3Bi%3A79857%3Bi%3A1694455765%3Bi%3A79795%3Bi%3A1694455771%3Bi%3A80215%3Bi%3A1694455777%3Bi%3A77023%3Bi%3A1694455858%3Bi%3A80116%3Bi%3A1694455783%3Bi%3A80303%3Bi%3A1694455786%3Bi%3A80075%3Bi%3A1694455789%3Bi%3A70346%3Bi%3A1694455793%3Bi%3A69020%3Bi%3A1694455849%3Bi%3A80076%3Bi%3A1694455799%3Bi%3A80271%3Bi%3A1694455805%3Bi%3A80053%3Bi%3A1694455812%3Bi%3A79958%3Bi%3A1694455815%3Bi%3A74034%3Bi%3A1694455824%3Bi%3A79348%3Bi%3A1694455885%3Bi%3A69143%3Bi%3A1694455842%3Bi%3A74042%3Bi%3A1694455846%3Bi%3A80273%3Bi%3A1694455855%3Bi%3A80313%3Bi%3A1694455867%3Bi%3A80117%3Bi%3A1694455870%3Bi%3A68154%3Bi%3A1694455882%3Bi%3A72441%3Bi%3A1694455894%3Bi%3A79951%3Bi%3A1694455900%3Bi%3A79627%3Bi%3A1694455903%3Bi%3A79615%3Bi%3A1694455906%3Bi%3A79604%3Bi%3A1694455912%3Bi%3A70310%3Bi%3A1694455921%3B%7D
2023-09-11T18:12:06.041Z pw:api   upgrade-insecure-requests: 1
2023-09-11T18:12:07.587Z pw:api ← 200 OK
2023-09-11T18:12:07.587Z pw:api   server: nginx
2023-09-11T18:12:07.587Z pw:api   date: Mon, 11 Sep 2023 18:12:07 GMT
2023-09-11T18:12:07.587Z pw:api   content-type: text/html; charset=UTF-8
2023-09-11T18:12:07.587Z pw:api   content-length: 7275
2023-09-11T18:12:07.587Z pw:api   connection: close
2023-09-11T18:12:07.587Z pw:api   set-cookie: mybb[lastvisit]=1694455927; expires=Tue, 10-Sep-2024 18:12:07 GMT; path=/; domain=.zredactedz6kdyavc6szj6ppbplfqoz3pgrk3zw57my4vybgblpfeayd.onion; Secure,mybb[lastactive]=1694455927; expires=Tue, 10-Sep-2024 18:12:07 GMT; path=/; domain=.zredactedz6kdyavc6szj6ppbplfqoz3pgrk3zw57my4vybgblpfeayd.onion; Secure,sid=e415c324a72b4fc41e73af0907778c57; path=/; domain=.zredactedz6kdyavc6szj6ppbplfqoz3pgrk3zw57my4vybgblpfeayd.onion; HttpOnly; Secure,mybb[threadread]=a%3A142%3A%7Bi%3A69504%3Bi%3A1694455161%3Bi%3A79395%3Bi%3A1694455098%3Bi%3A67509%3Bi%3A1694455117%3Bi%3A71401%3Bi%3A1694455166%3Bi%3A79667%3Bi%3A1694455120%3Bi%3A71243%3Bi%3A1694455158%3Bi%3A77189%3Bi%3A1694455199%3Bi%3A73492%3Bi%3A1694455149%3Bi%3A79658%3Bi%3A1694455146%3Bi%3A79957%3Bi%3A1694455172%3Bi%3A74174%3Bi%3A1694455195%3Bi%3A77377%3Bi%3A1694455233%3Bi%3A76139%3Bi%3A1694455230%3Bi%3A79397%3Bi%3A1694455192%3Bi%3A80165%3Bi%3A1694455202%3Bi%3A80221%3Bi%3A1694455206%3Bi%3A79399%3Bi%3A1694455209%3Bi%3A76257%3Bi%3A1694455221%3Bi%3A72415%3Bi%3A1694455218%3Bi%3A71137%3Bi%3A1694455236%3Bi%3A79154%3Bi%3A1694455329%3Bi%3A79081%3Bi%3A1694455248%3Bi%3A78435%3Bi%3A1694455273%3Bi%3A68659%3Bi%3A1694455349%3Bi%3A80299%3Bi%3A1694455261%3Bi%3A76298%3Bi%3A1694455352%3Bi%3A80295%3Bi%3A1694455267%3Bi%3A74818%3Bi%3A1694455284%3Bi%3A77201%3Bi%3A1694455343%3Bi%3A70063%3Bi%3A1694455337%3Bi%3A78562%3Bi%3A1694455364%3Bi%3A68787%3Bi%3A1694455312%3Bi%3A80298%3Bi%3A1694455320%3Bi%3A77566%3Bi%3A1694455340%3Bi%3A80311%3Bi%3A1694455346%3Bi%3A79932%3Bi%3A1694455355%3Bi%3A80120%3Bi%3A1694455358%3Bi%3A79660%3Bi%3A1694455361%3Bi%3A80241%3Bi%3A1694455367%3Bi%3A76677%3Bi%3A1694455370%3Bi%3A80156%3Bi%3A1694455373%3Bi%3A67654%3Bi%3A1694455376%3Bi%3A80218%3Bi%3A1694455379%3Bi%3A80213%3Bi%3A1694455382%3Bi%3A80164%3Bi%3A1694455455%3Bi%3A76990%3Bi%3A1694455396%3Bi%3A80068%3Bi%3A1694455404%3Bi%3A80229%3Bi%3A1694455410%3Bi%3A69756%3Bi%3A1694455440%3Bi%3A76166%3Bi%3A1694455419%3Bi%3A79888%3Bi%3A1694455429%3Bi%3A69679%3Bi%3A1694455458%3Bi%3A67682%3Bi%3A1694455473%3Bi%3A78099%3Bi%3A1694455443%3Bi%3A80070%3Bi%3A1694455447%3Bi%3A69997%3Bi%3A1694455461%3Bi%3A76672%3Bi%3A1694455467%3Bi%3A76665%3Bi%3A1694455470%3Bi%3A21347%3Bi%3A1694455479%3Bi%3A10941%3Bi%3A1694455481%3Bi%3A1149%3Bi%3A1694455531%3Bi%3A772%3Bi%3A1694455578%3Bi%3A99%3Bi%3A1694455510%3Bi%3A17603%3Bi%3A1694455540%3Bi%3A84%3Bi%3A1694455556%3Bi%3A14592%3Bi%3A1694455559%3Bi%3A389%3Bi%3A1694455518%3Bi%3A37%3Bi%3A1694455534%3Bi%3A1709%3Bi%3A1694455522%3Bi%3A6025%3Bi%3A1694455515%3Bi%3A2092%3Bi%3A1694455575%3Bi%3A333%3Bi%3A1694455547%3Bi%3A502%3Bi%3A1694455572%3Bi%3A427%3Bi%3A1694455553%3Bi%3A11463%3Bi%3A1694455565%3Bi%3A1031%3Bi%3A1694455562%3Bi%3A9830%3Bi%3A1694455569%3Bi%3A538%3Bi%3A1694455680%3Bi%3A326%3Bi%3A1694455601%3Bi%3A681%3Bi%3A1694455604%3Bi%3A445%3Bi%3A1694455648%3Bi%3A1368%3Bi%3A1694455669%3Bi%3A860%3Bi%3A1694455595%3Bi%3A522%3Bi%3A1694455651%3Bi%3A11193%3Bi%3A1694455627%3Bi%3A21062%3Bi%3A1694455671%3Bi%3A603%3Bi%3A1694455618%3Bi%3A77358%3Bi%3A1694455624%3Bi%3A2706%3Bi%3A1694455633%3Bi%3A336%3Bi%3A1694455639%3Bi%3A21194%3Bi%3A1694455657%3Bi%3A168%3Bi%3A1694455666%3Bi%3A24561%3Bi%3A1694455645%3Bi%3A3879%3Bi%3A1694455654%3Bi%3A91%3Bi%3A1694455663%3Bi%3A11283%3Bi%3A1694455675%3Bi%3A29812%3Bi%3A1694455683%3Bi%3A80030%3Bi%3A1694455687%3Bi%3A80035%3Bi%3A1694455691%3Bi%3A75787%3Bi%3A1694455697%3Bi%3A80233%3Bi%3A1694455700%3Bi%3A79930%3Bi%3A1694455703%3Bi%3A80173%3Bi%3A1694455706%3Bi%3A79879%3Bi%3A1694455709%3Bi%3A80268%3Bi%3A1694455714%3Bi%3A79859%3Bi%3A1694455717%3Bi%3A80232%3Bi%3A1694455720%3Bi%3A79878%3Bi%3A1694455724%3Bi%3A80262%3Bi%3A1694455733%3Bi%3A80110%3Bi%3A1694455738%3Bi%3A79434%3Bi%3A1694455742%3Bi%3A80239%3Bi%3A1694455748%3Bi%3A80235%3Bi%3A1694455751%3Bi%3A80270%3Bi%3A1694455754%3Bi%3A79857%3Bi%3A1694455765%3Bi%3A79795%3Bi%3A1694455771%3Bi%3A80215%3Bi%3A1694455777%3Bi%3A77023%3Bi%3A1694455858%3Bi%3A80116%3Bi%3A1694455783%3Bi%3A80303%3Bi%3A1694455786%3Bi%3A80075%3Bi%3A1694455789%3Bi%3A70346%3Bi%3A1694455793%3Bi%3A69020%3Bi%3A1694455849%3Bi%3A80076%3Bi%3A1694455799%3Bi%3A80271%3Bi%3A1694455805%3Bi%3A80053%3Bi%3A1694455812%3Bi%3A79958%3Bi%3A1694455815%3Bi%3A74034%3Bi%3A1694455824%3Bi%3A79348%3Bi%3A1694455885%3Bi%3A69143%3Bi%3A1694455842%3Bi%3A74042%3Bi%3A1694455846%3Bi%3A80273%3Bi%3A1694455855%3Bi%3A80313%3Bi%3A1694455867%3Bi%3A80117%3Bi%3A1694455870%3Bi%3A68154%3Bi%3A1694455882%3Bi%3A72441%3Bi%3A1694455894%3Bi%3A79951%3Bi%3A1694455900%3Bi%3A79627%3Bi%3A1694455903%3Bi%3A79615%3Bi%3A1694455906%3Bi%3A79604%3Bi%3A1694455912%3Bi%3A70310%3Bi%3A1694455921%3Bi%3A76855%3Bi%3A1694455927%3B%7D; path=/; domain=.breachedu76kdyavc6szj6ppbplfqoz3pgrk3zw57my4vybgblpfeayd.onion
2023-09-11T18:12:07.587Z pw:api   vary: Accept-Encoding
2023-09-11T18:12:07.587Z pw:api   content-encoding: gzip
2023-09-11T18:12:07.587Z pw:api   x-frame-options: SAMEORIGIN, SAMEORIGIN, SAMEORIGIN
2023-09-11T18:12:07.587Z pw:api   x-xss-protection: 1; mode=block, 1; mode=block, 1; mode=block
2023-09-11T18:12:07.587Z pw:api   referrer-policy: no-referrer, no-referrer, no-referrer
mxschmitt commented 1 year ago

Do you have page.route or context.route by any chance in place?

Did you just replace the domain in the set-cookie header with a different one or did you do more modifications? Most likely this is caused by a set-cookie header which we didn't expect, so trying to narrow down that path.

bv-do commented 1 year ago

Thank you for looking at this!
We do have page.route functions but they don't do any manipulation of the cookies/headers. There is request filtering based on resource type and also response filtering to help avoid downloading attachments and very large responses.

page setup code

page.route("**/*", lambda route: filter_response(page, route))
page.route("**/*", filter_resource_type)

route filter functions

def filter_response(page, route):
    try:

        response = page.request.fetch(route.request, timeout=120000)

    except CancelledError as e:
        log.debug(f"Received CancelledError for {route.request.url}.  Calling route.abort().")
        route.abort()
        return
    except Exception as e:
        log.exception(f"Exception during fetch of {route.request.url}.  Calling route.abort().")
        route.abort()
        return

    size = response.headers.get('content-length')
    disposition = response.headers.get('content-disposition')
    if disposition and 'attachment' in disposition:
        log.debug(f"Blocking attachment download for url {route.request.url}")
        route.abort(error_code='blockedbyclient')
    # prevent large downloads
    elif size and int(size) > 5_000_000:
        log.info(f"Blocking large body ({size=}) for url {route.request.url}")
        route.abort(error_code='blockedbyclient')
    else:
        route.fulfill(response=response)

def filter_resource_type(route):
    if route.request.resource_type in ("image", "stylesheet", "media", "font"):
        route.abort()
    else:
        route.fallback()
mxschmitt commented 1 year ago

Sorry for the late reply. So my guess is the following:

  1. You navigate to a website
  2. Requests are getting intercepted via page.route
  3. Playwright does do the request, parses the set-cookie header which we parse, then send it to Chromium, there Chromium is unable to set the cookie tho due to some reason, the request never gets fulfilled, thats why it hangs.

To debug this issue further, we could either try to emulate such a website, with the set-cookie header (I tried that before, but didn't succeed) or we look at what we send to Chromium.

Would it be possible to set the DEBUG=pw:protocol header and provide us the output? Also over Discord if you want.

Also maybe try to create a reproduction script which we can run locally? If its sensitive, feel free to send it over to me on Discord. Thanks!

db-do commented 1 year ago

Here's the pw:protocol info:

pw:protocol SEND ► {"id":10248,"method":"Storage.setCookies","params":{"cookies":[{"name":"mybb[lastvisit]","value":"1695056265","domain":".zredactedz6kdyavc6szj6ppbplfqoz3pgrk3zw57my4vybgblpfeayd.onion","path":"/","expires":1726592265,"httpOnly":false,"secure":true,"sameSite":"Lax"},{"name":"mybb[lastactive]","value":"1695056265","domain":".zredactedz6kdyavc6szj6ppbplfqoz3pgrk3zw57my4vybgblpfeayd.onion","path":"/","expires":1726592265,"httpOnly":false,"secure":true,"sameSite":"Lax"},{"name":"sid","value":"26804ff20753fe2d5dde451da33a59dc","domain":".zredactedz6kdyavc6szj6ppbplfqoz3pgrk3zw57my4vybgblpfeayd.onion","path":"/","expires":-1,"httpOnly":true,"secure":true,"sameSite":"Lax"},{"name":"mybb[threadread]","value":"a%3A142%3A%7Bi%3A69504%3Bi%3A1695055513%3Bi%3A81282%3Bi%3A1695055473%3Bi%3A80165%3Bi%3A1695055476%3Bi%3A71401%3Bi%3A1695055504%3Bi%3A77189%3Bi%3A1695055579%3Bi%3A79658%3Bi%3A1695055488%3Bi%3A80446%3Bi%3A1695055498%3Bi%3A74174%3Bi%3A1695055565%3Bi%3A77377%3Bi%3A1695055567%3Bi%3A72415%3Bi%3A1695055516%3Bi%3A67509%3Bi%3A1695055548%3Bi%3A79667%3Bi%3A1695055540%3Bi%3A80322%3Bi%3A1695055542%3Bi%3A80817%3Bi%3A1695055553%3Bi%3A71243%3Bi%3A1695055585%3Bi%3A75871%3Bi%3A1695055593%3Bi%3A80221%3Bi%3A1695055562%3Bi%3A75989%3Bi%3A1695055576%3Bi%3A79957%3Bi%3A1695055603%3Bi%3A80962%3Bi%3A1695055606%3Bi%3A81343%3Bi%3A1695055612%3Bi%3A81285%3Bi%3A1695055615%3Bi%3A81444%3Bi%3A1695055618%3Bi%3A81356%3Bi%3A1695055621%3Bi%3A81270%3Bi%3A1695055623%3Bi%3A80779%3Bi%3A1695055627%3Bi%3A81148%3Bi%3A1695055696%3Bi%3A81417%3Bi%3A1695055635%3Bi%3A81011%3Bi%3A1695055638%3Bi%3A78496%3Bi%3A1695055654%3Bi%3A69664%3Bi%3A1695055707%3Bi%3A81408%3Bi%3A1695055663%3Bi%3A81432%3Bi%3A1695055666%3Bi%3A80670%3Bi%3A1695055668%3Bi%3A80833%3Bi%3A1695055677%3Bi%3A81430%3Bi%3A1695055680%3Bi%3A81405%3Bi%3A1695055691%3Bi%3A70063%3Bi%3A1695055702%3Bi%3A72394%3Bi%3A1695055785%3Bi%3A81028%3Bi%3A1695055716%3Bi%3A81342%3Bi%3A1695055719%3Bi%3A76778%3Bi%3A1695055808%3Bi%3A76408%3Bi%3A1695055817%3Bi%3A81048%3Bi%3A1695055734%3Bi%3A80746%3Bi%3A1695055754%3Bi%3A81372%3Bi%3A1695055740%3Bi%3A81365%3Bi%3A1695055743%3Bi%3A81382%3Bi%3A1695055751%3Bi%3A81241%3Bi%3A1695055757%3Bi%3A77537%3Bi%3A1695055760%3Bi%3A81272%3Bi%3A1695055763%3Bi%3A81378%3Bi%3A1695055774%3Bi%3A81170%3Bi%3A1695055780%3Bi%3A81339%3Bi%3A1695055783%3Bi%3A81344%3Bi%3A1695055790%3Bi%3A81404%3Bi%3A1695055802%3Bi%3A80663%3Bi%3A1695055805%3Bi%3A81362%3Bi%3A1695055813%3Bi%3A15825%3Bi%3A1695055820%3Bi%3A52864%3Bi%3A1695055913%3Bi%3A12549%3Bi%3A1695055910%3Bi%3A15652%3Bi%3A1695055872%3Bi%3A71062%3Bi%3A1695055883%3Bi%3A326%3Bi%3A1695055848%3Bi%3A390%3Bi%3A1695055863%3Bi%3A210%3Bi%3A1695055901%3Bi%3A23573%3Bi%3A1695055854%3Bi%3A77358%3Bi%3A1695055878%3Bi%3A418%3Bi%3A1695055918%3Bi%3A67467%3Bi%3A1695055880%3Bi%3A75794%3Bi%3A1695055886%3Bi%3A72%3Bi%3A1695055895%3Bi%3A5057%3Bi%3A1695055889%3Bi%3A47083%3Bi%3A1695055907%3Bi%3A1122%3Bi%3A1695055898%3Bi%3A3077%3Bi%3A1695055905%3Bi%3A1284%3Bi%3A1695055916%3Bi%3A14592%3Bi%3A1695055990%3Bi%3A94%3Bi%3A1695055999%3Bi%3A642%3Bi%3A1695055956%3Bi%3A1243%3Bi%3A1695055958%3Bi%3A29%3Bi%3A1695055979%3Bi%3A67458%3Bi%3A1695055935%3Bi%3A42805%3Bi%3A1695055967%3Bi%3A424%3Bi%3A1695055996%3Bi%3A67456%3Bi%3A1695056008%3Bi%3A11502%3Bi%3A1695055970%3Bi%3A13623%3Bi%3A1695055961%3Bi%3A87%3Bi%3A1695056014%3Bi%3A91%3Bi%3A1695055985%3Bi%3A2116%3Bi%3A1695056019%3Bi%3A2473%3Bi%3A1695055976%3Bi%3A436%3Bi%3A1695055982%3Bi%3A1512%3Bi%3A1695056002%3Bi%3A67461%3Bi%3A1695055993%3Bi%3A23626%3Bi%3A1695056005%3Bi%3A1199%3Bi%3A1695056016%3Bi%3A81261%3Bi%3A1695056022%3Bi%3A80467%3Bi%3A1695056025%3Bi%3A77643%3Bi%3A1695056102%3Bi%3A80542%3Bi%3A1695056031%3Bi%3A78993%3Bi%3A1695056034%3Bi%3A81377%3Bi%3A1695056037%3Bi%3A81212%3Bi%3A1695056042%3Bi%3A81227%3Bi%3A1695056048%3Bi%3A80790%3Bi%3A1695056053%3Bi%3A81099%3Bi%3A1695056056%3Bi%3A81407%3Bi%3A1695056062%3Bi%3A81350%3Bi%3A1695056065%3Bi%3A81209%3Bi%3A1695056067%3Bi%3A81349%3Bi%3A1695056078%3Bi%3A75787%3Bi%3A1695056105%3Bi%3A80646%3Bi%3A1695056084%3Bi%3A81191%3Bi%3A1695056087%3Bi%3A74932%3Bi%3A1695056096%3Bi%3A80873%3Bi%3A1695056099%3Bi%3A81429%3Bi%3A1695056113%3Bi%3A81425%3Bi%3A1695056116%3Bi%3A72610%3Bi%3A1695056124%3Bi%3A76252%3Bi%3A1695056155%3Bi%3A70790%3Bi%3A1695056139%3Bi%3A81007%3Bi%3A1695056136%3Bi%3A81124%3Bi%3A1695056143%3Bi%3A78124%3Bi%3A1695056199%3Bi%3A68973%3Bi%3A1695056162%3Bi%3A80397%3Bi%3A1695056196%3Bi%3A79958%3Bi%3A1695056172%3Bi%3A79870%3Bi%3A1695056189%3Bi%3A68231%3Bi%3A1695056193%3Bi%3A78338%3Bi%3A1695056205%3Bi%3A81439%3Bi%3A1695056208%3Bi%3A74773%3Bi%3A1695056217%3Bi%3A81393%3Bi%3A1695056222%3Bi%3A81032%3Bi%3A1695056225%3Bi%3A81371%3Bi%3A1695056229%3Bi%3A80758%3Bi%3A1695056232%3Bi%3A81003%3Bi%3A1695056235%3Bi%3A78327%3Bi%3A1695056238%3Bi%3A79059%3Bi%3A1695056250%3Bi%3A72441%3Bi%3A1695056259%3Bi%3A80908%3Bi%3A1695056262%3Bi%3A80601%3Bi%3A1695056265%3B%7D","domain":".zredactedz6kdyavc6szj6ppbplfqoz3pgrk3zw57my4vybgblpfeayd.onion","path":"/","expires":-1,"httpOnly":false,"secure":false,"sameSite":"Lax"}],"browserContextId":"88D21CE9FE3C5CB11DADEB6FF7B43DD0"}}
2023-09-18T16:57:46.484Z pw:protocol ◀ RECV {"id":10248,"error":{"code":-32602,"message":"Invalid cookie fields"}}
node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

ProtocolError: Protocol error (Storage.setCookies): Invalid cookie fields
    at /Users/in0576/projects/hydra/venv/lib/python3.8/site-packages/playwright/driver/package/lib/server/chromium/crConnection.js:169:16
    at new Promise (<anonymous>)
    at CRSession.send (/Users/in0576/projects/hydra/venv/lib/python3.8/site-packages/playwright/driver/package/lib/server/chromium/crConnection.js:165:12)
    at CRBrowserContext.addCookies (/Users/in0576/projects/hydra/venv/lib/python3.8/site-packages/playwright/driver/package/lib/server/chromium/crBrowser.js:367:34)
    at BrowserContextAPIRequestContext._addCookies (/Users/in0576/projects/hydra/venv/lib/python3.8/site-packages/playwright/driver/package/lib/server/fetch.js:400:25)
    at ClientRequest.<anonymous> (/Users/in0576/projects/hydra/venv/lib/python3.8/site-packages/playwright/driver/package/lib/server/fetch.js:213:40)
    at Object.onceWrapper (node:events:629:26)
    at ClientRequest.emit (node:events:514:28)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:700:27)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17) {
  sessionClosed: false
}

Node.js v18.17.0
db-do commented 1 year ago

Here is a test program. It always raises the Exception. It sometimes freezes. If you need it to freeze try several, maybe up to 15, times.

badcookie.py.zip

yury-s commented 1 year ago

The cookie value string is too long, max length supported in browsers is 4096 bytes while your server returns 4111. We shouldn't throw in this case and just ignore the cookie.

bv-do commented 1 year ago

Awesome, thank you!