patchright-cli 0.8.0__py3-none-any.whl → 0.9.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- patchright_cli/__init__.py +1 -1
- patchright_cli/cli.py +18 -4
- patchright_cli/daemon.py +519 -29
- patchright_cli/mcp_server.py +127 -32
- {patchright_cli-0.8.0.dist-info → patchright_cli-0.9.0.dist-info}/METADATA +103 -6
- {patchright_cli-0.8.0.dist-info → patchright_cli-0.9.0.dist-info}/RECORD +9 -9
- {patchright_cli-0.8.0.dist-info → patchright_cli-0.9.0.dist-info}/WHEEL +0 -0
- {patchright_cli-0.8.0.dist-info → patchright_cli-0.9.0.dist-info}/entry_points.txt +0 -0
- {patchright_cli-0.8.0.dist-info → patchright_cli-0.9.0.dist-info}/licenses/LICENSE +0 -0
patchright_cli/__init__.py
CHANGED
patchright_cli/cli.py
CHANGED
|
@@ -17,7 +17,7 @@ from pathlib import Path
|
|
|
17
17
|
import click
|
|
18
18
|
|
|
19
19
|
from patchright_cli import __version__
|
|
20
|
-
from patchright_cli.daemon import DEFAULT_PORT, ensure_daemon_running
|
|
20
|
+
from patchright_cli.daemon import DEFAULT_PORT, ensure_daemon_running, read_daemon_token
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
def _soften_output_encoding(*streams) -> None:
|
|
@@ -392,6 +392,11 @@ def _send_command(command: str, args: list, options: dict, port: int = DEFAULT_P
|
|
|
392
392
|
"options": options,
|
|
393
393
|
"cwd": os.getcwd(),
|
|
394
394
|
}
|
|
395
|
+
# A daemon that predates tokens writes no token file and accepts the
|
|
396
|
+
# message without one, so a missing file is not an error here.
|
|
397
|
+
token = read_daemon_token(port)
|
|
398
|
+
if token:
|
|
399
|
+
msg["token"] = token
|
|
395
400
|
data = json.dumps(msg).encode("utf-8")
|
|
396
401
|
|
|
397
402
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
@@ -426,7 +431,7 @@ def _recv_exact(sock: socket.socket, n: int) -> bytes:
|
|
|
426
431
|
|
|
427
432
|
COMMANDS_HELP = {
|
|
428
433
|
# Core
|
|
429
|
-
"open": "open [url] Open browser (starts daemon if needed)",
|
|
434
|
+
"open": "open [url] Open browser (starts daemon if needed) [--block-networks=link-local|private] [--web-only]",
|
|
430
435
|
"attach": "attach --cdp=<url> [--context=new|host] Attach to running Chrome via CDP",
|
|
431
436
|
"goto": "goto <url> Navigate to URL",
|
|
432
437
|
"click": "click <ref> [button] Click element [--modifiers=Alt,Shift]",
|
|
@@ -688,6 +693,10 @@ def main():
|
|
|
688
693
|
i = 0
|
|
689
694
|
while i < len(argv):
|
|
690
695
|
arg = argv[i]
|
|
696
|
+
if arg == "--":
|
|
697
|
+
# End of options: the rest is positional, even text that looks like a flag.
|
|
698
|
+
remaining.extend(argv[i:])
|
|
699
|
+
break
|
|
691
700
|
if arg == "--headless":
|
|
692
701
|
headless = True
|
|
693
702
|
elif arg == "--persistent":
|
|
@@ -832,8 +841,13 @@ def main():
|
|
|
832
841
|
# Separate --key=value and --flag from positional args
|
|
833
842
|
positional_args = []
|
|
834
843
|
cmd_opts: dict = {}
|
|
844
|
+
end_of_options = False
|
|
835
845
|
for a in args:
|
|
836
|
-
if
|
|
846
|
+
if end_of_options:
|
|
847
|
+
positional_args.append(a)
|
|
848
|
+
elif a == "--":
|
|
849
|
+
end_of_options = True
|
|
850
|
+
elif a.startswith("--") and "=" in a:
|
|
837
851
|
k, v = a[2:].split("=", 1)
|
|
838
852
|
cmd_opts[k] = v
|
|
839
853
|
elif a.startswith("--"):
|
|
@@ -855,7 +869,7 @@ def main():
|
|
|
855
869
|
except FileNotFoundError:
|
|
856
870
|
click.echo(f"File not found: {file_opt}", err=True)
|
|
857
871
|
sys.exit(1)
|
|
858
|
-
elif args and args[0] == "-":
|
|
872
|
+
elif args and args[0] == "-" and not end_of_options:
|
|
859
873
|
# Read JS from stdin
|
|
860
874
|
args = [sys.stdin.read()]
|
|
861
875
|
elif not args and not sys.stdin.isatty():
|