File tree Expand file tree Collapse file tree 4 files changed +32
-8
lines changed Expand file tree Collapse file tree 4 files changed +32
-8
lines changed Original file line number Diff line number Diff line change 1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- import os
1615import subprocess
1716import sys
1817
19- from playwright ._impl ._driver import compute_driver_executable
20- from playwright ._repo_version import version
18+ from playwright ._impl ._driver import compute_driver_executable , get_driver_env
2119
2220
2321def main () -> None :
2422 driver_executable = compute_driver_executable ()
25- env = os .environ .copy ()
26- env ["PW_CLI_TARGET_LANG" ] = "python"
27- env ["PW_CLI_DISPLAY_VERSION" ] = version
28- completed_process = subprocess .run ([str (driver_executable ), * sys .argv [1 :]], env = env )
23+ completed_process = subprocess .run (
24+ [str (driver_executable ), * sys .argv [1 :]], env = get_driver_env ()
25+ )
2926 sys .exit (completed_process .returncode )
3027
3128
Original file line number Diff line number Diff line change 1414
1515import asyncio
1616import inspect
17+ import os
1718import sys
1819from pathlib import Path
1920
2021import playwright
22+ from playwright ._repo_version import version
2123
2224
2325def compute_driver_executable () -> Path :
@@ -42,3 +44,13 @@ def compute_driver_executable() -> Path:
4244 # uvloop does not support child watcher
4345 # see https://github.com/microsoft/playwright-python/issues/582
4446 pass
47+
48+
49+ def get_driver_env () -> dict :
50+ env = os .environ .copy ()
51+ env ["PW_CLI_TARGET_LANG" ] = "python"
52+ env [
53+ "PW_CLI_TARGET_LANG_VERSION"
54+ ] = f"{ sys .version_info .major } .{ sys .version_info .minor } "
55+ env ["PW_CLI_DISPLAY_VERSION" ] = version
56+ return env
Original file line number Diff line number Diff line change 2828from websockets .client import connect as websocket_connect
2929
3030from playwright ._impl ._api_types import Error
31+ from playwright ._impl ._driver import get_driver_env
3132from playwright ._impl ._helper import ParsedMessagePayload
3233
3334
@@ -116,7 +117,7 @@ async def connect(self) -> None:
116117
117118 try :
118119 # For pyinstaller
119- env = os . environ . copy ()
120+ env = get_driver_env ()
120121 if getattr (sys , "frozen" , False ):
121122 env .setdefault ("PLAYWRIGHT_BROWSERS_PATH" , "0" )
122123
Original file line number Diff line number Diff line change 1414
1515import asyncio
1616import json
17+ import sys
1718from pathlib import Path
1819from typing import Any
1920
@@ -263,3 +264,16 @@ async def test_should_accept_already_serialized_data_as_bytes_when_content_type_
263264 body = req .post_body
264265 assert body == stringified_value
265266 await request .dispose ()
267+
268+
269+ async def test_should_contain_default_user_agent (
270+ playwright : Playwright , server : Server
271+ ):
272+ request = await playwright .request .new_context ()
273+ [request , _ ] = await asyncio .gather (
274+ server .wait_for_request ("/empty.html" ),
275+ request .get (server .EMPTY_PAGE ),
276+ )
277+ user_agent = request .getHeader ("user-agent" )
278+ assert "python" in user_agent
279+ assert f"{ sys .version_info .major } .{ sys .version_info .minor } " in user_agent
You can’t perform that action at this time.
0 commit comments