35 lines
1005 B
Python
35 lines
1005 B
Python
"""Playwright 仅打开浏览器子进程:由 browser_service.cmd_open 启动,argv[1] 为 JSON 配置路径。"""
|
||
import json
|
||
import sys
|
||
|
||
from playwright.sync_api import sync_playwright
|
||
|
||
|
||
def main():
|
||
with open(sys.argv[1], encoding="utf-8") as f:
|
||
c = json.load(f)
|
||
with sync_playwright() as p:
|
||
ctx = p.chromium.launch_persistent_context(
|
||
user_data_dir=c["profile_dir"],
|
||
headless=False,
|
||
channel=c["channel"],
|
||
no_viewport=True,
|
||
args=["--start-maximized"],
|
||
)
|
||
try:
|
||
page = ctx.pages[0] if ctx.pages else ctx.new_page()
|
||
page.goto(c["url"], wait_until="domcontentloaded", timeout=60000)
|
||
ctx.wait_for_event("close", timeout=86400000)
|
||
except Exception as e:
|
||
print(e, file=sys.stderr)
|
||
raise
|
||
finally:
|
||
try:
|
||
ctx.close()
|
||
except Exception:
|
||
pass
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|