Description
Hi 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.