File tree 4 files changed +32
-8
lines changed 4 files changed +32
-8
lines changed Original file line number Diff line number Diff line change 12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- import os
16
15
import subprocess
17
16
import sys
18
17
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
21
19
22
20
23
21
def main () -> None :
24
22
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
+ )
29
26
sys .exit (completed_process .returncode )
30
27
31
28
Original file line number Diff line number Diff line change 14
14
15
15
import asyncio
16
16
import inspect
17
+ import os
17
18
import sys
18
19
from pathlib import Path
19
20
20
21
import playwright
22
+ from playwright ._repo_version import version
21
23
22
24
23
25
def compute_driver_executable () -> Path :
@@ -42,3 +44,13 @@ def compute_driver_executable() -> Path:
42
44
# uvloop does not support child watcher
43
45
# see https://github.com/microsoft/playwright-python/issues/582
44
46
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 28
28
from websockets .client import connect as websocket_connect
29
29
30
30
from playwright ._impl ._api_types import Error
31
+ from playwright ._impl ._driver import get_driver_env
31
32
from playwright ._impl ._helper import ParsedMessagePayload
32
33
33
34
@@ -116,7 +117,7 @@ async def connect(self) -> None:
116
117
117
118
try :
118
119
# For pyinstaller
119
- env = os . environ . copy ()
120
+ env = get_driver_env ()
120
121
if getattr (sys , "frozen" , False ):
121
122
env .setdefault ("PLAYWRIGHT_BROWSERS_PATH" , "0" )
122
123
Original file line number Diff line number Diff line change 14
14
15
15
import asyncio
16
16
import json
17
+ import sys
17
18
from pathlib import Path
18
19
from typing import Any
19
20
@@ -263,3 +264,16 @@ async def test_should_accept_already_serialized_data_as_bytes_when_content_type_
263
264
body = req .post_body
264
265
assert body == stringified_value
265
266
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