Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions playwright/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import subprocess
import sys

from playwright._impl._driver import compute_driver_executable
from playwright._repo_version import version
from playwright._impl._driver import compute_driver_executable, get_driver_env


def main() -> None:
driver_executable = compute_driver_executable()
env = os.environ.copy()
env["PW_CLI_TARGET_LANG"] = "python"
env["PW_CLI_DISPLAY_VERSION"] = version
completed_process = subprocess.run([str(driver_executable), *sys.argv[1:]], env=env)
completed_process = subprocess.run(
[str(driver_executable), *sys.argv[1:]], env=get_driver_env()
)
sys.exit(completed_process.returncode)


Expand Down
12 changes: 12 additions & 0 deletions playwright/_impl/_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

import asyncio
import inspect
import os
import sys
from pathlib import Path

import playwright
from playwright._repo_version import version


def compute_driver_executable() -> Path:
Expand All @@ -42,3 +44,13 @@ def compute_driver_executable() -> Path:
# uvloop does not support child watcher
# see https://github.com/microsoft/playwright-python/issues/582
pass


def get_driver_env() -> dict:
env = os.environ.copy()
env["PW_CLI_TARGET_LANG"] = "python"
env[
"PW_CLI_TARGET_LANG_VERSION"
] = f"{sys.version_info.major}.{sys.version_info.minor}"
env["PW_CLI_DISPLAY_VERSION"] = version
return env
3 changes: 2 additions & 1 deletion playwright/_impl/_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from websockets.client import connect as websocket_connect

from playwright._impl._api_types import Error
from playwright._impl._driver import get_driver_env
from playwright._impl._helper import ParsedMessagePayload


Expand Down Expand Up @@ -116,7 +117,7 @@ async def connect(self) -> None:

try:
# For pyinstaller
env = os.environ.copy()
env = get_driver_env()
if getattr(sys, "frozen", False):
env.setdefault("PLAYWRIGHT_BROWSERS_PATH", "0")

Expand Down
14 changes: 14 additions & 0 deletions tests/async/test_fetch_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import asyncio
import json
import sys
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -263,3 +264,16 @@ async def test_should_accept_already_serialized_data_as_bytes_when_content_type_
body = req.post_body
assert body == stringified_value
await request.dispose()


async def test_should_contain_default_user_agent(
playwright: Playwright, server: Server
):
request = await playwright.request.new_context()
[request, _] = await asyncio.gather(
server.wait_for_request("/empty.html"),
request.get(server.EMPTY_PAGE),
)
user_agent = request.getHeader("user-agent")
assert "python" in user_agent
assert f"{sys.version_info.major}.{sys.version_info.minor}" in user_agent