Cannot Overwrite Headers for Python's `Route.continue_`
See original GitHub issueHi all! I first want to say that I love Playwright – it is incredibly seamless and lightning fast. From my experience so far, it has a simple yet powerful API, and is a lot less clunky than Selenium.
My team is trying to use it to render PDFs, and we need to set the Origin
header to avoid CORS issues. I have found an issue that has plagued me on Ubuntu and MacOS Big Sur, with Python 3.9.5 and Playwright (Python) 1.12.1.
Using a modified Spec example, here is our issue:
from playwright.sync_api import sync_playwright
def handle(route, request):
headers = {
**request.headers,
'foo': 'bar', # set 'foo' header
'origin': 'literally_anywhere'
}
route.continue_(headers=headers)
with sync_playwright() as pw:
browser = pw.chromium.launch()
page = browser.new_page()
page.route("**/*", handle)
page.on('request', lambda request: print(f'====request headers: ({request.url})====\n{request.headers}\n'))
browser.close()
'foo'
is being set erratically – only on two of the page requests that are logged. 'origin'
is never set.
In addition, the spec example cites being able to set 'origin': None
, but for me it throws
playwright._impl._api_types.Error: headers[4].value: expected string, got object
Installation procedure was as follows:
# (in a python3 venv virtual environment)
pip install playwright
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 python -m playwright install
playwright install chromium
Thank you in advance for any help! Please let me know if this is just a configuration issue.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
I digged into it. The reason is at least in the reproducible, that it’s based on redirects which is currently an upstream limitation. When you are using
https://www.google.com
it works. Their redirect chain is:http://google.com
->https://google.com
->https://www.google.com
.PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 python -m playwright install
this will like result in doing nothing. You are saying basically, hey install browsers but the skip env var is set, so its not installing anything at all.Closed for now, lets reopen if the problem is still persistent.