diff --git a/playwright/__main__.py b/playwright/__main__.py index e012cc449..a5dfdad40 100644 --- a/playwright/__main__.py +++ b/playwright/__main__.py @@ -19,9 +19,9 @@ def main() -> None: - driver_executable = compute_driver_executable() + driver_executable, driver_cli = compute_driver_executable() completed_process = subprocess.run( - [str(driver_executable), *sys.argv[1:]], env=get_driver_env() + [driver_executable, driver_cli, *sys.argv[1:]], env=get_driver_env() ) sys.exit(completed_process.returncode) diff --git a/playwright/_impl/_driver.py b/playwright/_impl/_driver.py index d8004d296..9e8cdc1e7 100644 --- a/playwright/_impl/_driver.py +++ b/playwright/_impl/_driver.py @@ -16,17 +16,18 @@ import os import sys from pathlib import Path +from typing import Tuple import playwright from playwright._repo_version import version -def compute_driver_executable() -> Path: - package_path = Path(inspect.getfile(playwright)).parent - platform = sys.platform - if platform == "win32": - return package_path / "driver" / "playwright.cmd" - return package_path / "driver" / "playwright.sh" +def compute_driver_executable() -> Tuple[str, str]: + driver_path = Path(inspect.getfile(playwright)).parent / "driver" + cli_path = str(driver_path / "package" / "cli.js") + if sys.platform == "win32": + return (str(driver_path / "node.exe"), cli_path) + return (os.getenv("PLAYWRIGHT_NODEJS_PATH", str(driver_path / "node")), cli_path) def get_driver_env() -> dict: diff --git a/playwright/_impl/_transport.py b/playwright/_impl/_transport.py index d49b5a2d5..f07d31dcd 100644 --- a/playwright/_impl/_transport.py +++ b/playwright/_impl/_transport.py @@ -19,10 +19,9 @@ import subprocess import sys from abc import ABC, abstractmethod -from pathlib import Path from typing import Callable, Dict, Optional, Union -from playwright._impl._driver import get_driver_env +from playwright._impl._driver import compute_driver_executable, get_driver_env from playwright._impl._helper import ParsedMessagePayload @@ -90,12 +89,9 @@ def deserialize_message(self, data: Union[str, bytes]) -> ParsedMessagePayload: class PipeTransport(Transport): - def __init__( - self, loop: asyncio.AbstractEventLoop, driver_executable: Path - ) -> None: + def __init__(self, loop: asyncio.AbstractEventLoop) -> None: super().__init__(loop) self._stopped = False - self._driver_executable = driver_executable def request_stop(self) -> None: assert self._output @@ -120,8 +116,10 @@ async def connect(self) -> None: startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE + executable_path, entrypoint_path = compute_driver_executable() self._proc = await asyncio.create_subprocess_exec( - str(self._driver_executable), + executable_path, + entrypoint_path, "run-driver", stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, diff --git a/playwright/async_api/_context_manager.py b/playwright/async_api/_context_manager.py index 2876d85e5..0c93f7043 100644 --- a/playwright/async_api/_context_manager.py +++ b/playwright/async_api/_context_manager.py @@ -16,7 +16,6 @@ from typing import Any from playwright._impl._connection import Connection -from playwright._impl._driver import compute_driver_executable from playwright._impl._object_factory import create_remote_object from playwright._impl._transport import PipeTransport from playwright.async_api._generated import Playwright as AsyncPlaywright @@ -32,7 +31,7 @@ async def __aenter__(self) -> AsyncPlaywright: self._connection = Connection( None, create_remote_object, - PipeTransport(loop, compute_driver_executable()), + PipeTransport(loop), loop, ) loop.create_task(self._connection.run()) diff --git a/playwright/sync_api/_context_manager.py b/playwright/sync_api/_context_manager.py index c27a25e32..feb648ca0 100644 --- a/playwright/sync_api/_context_manager.py +++ b/playwright/sync_api/_context_manager.py @@ -18,7 +18,6 @@ from greenlet import greenlet from playwright._impl._connection import ChannelOwner, Connection -from playwright._impl._driver import compute_driver_executable from playwright._impl._errors import Error from playwright._impl._greenlets import MainGreenlet from playwright._impl._object_factory import create_remote_object @@ -61,7 +60,7 @@ def greenlet_main() -> None: self._connection = Connection( dispatcher_fiber, create_remote_object, - PipeTransport(self._loop, compute_driver_executable()), + PipeTransport(self._loop), self._loop, )