From 62d41900e1731bdc37bb6d85f15e3e34659a7aa2 Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 13 Mar 2023 17:19:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=E6=97=B6=E8=87=AA=E5=8A=A8=E5=8A=A0=E4=B8=8A--remote-allow-ori?= =?UTF-8?q?gins=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/commons/browser.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/DrissionPage/commons/browser.py b/DrissionPage/commons/browser.py index f35dfd3..0f4c8a8 100644 --- a/DrissionPage/commons/browser.py +++ b/DrissionPage/commons/browser.py @@ -63,13 +63,17 @@ def get_launch_args(opt): # ----------处理arguments----------- result = set() has_user_path = False + remote_allow = False for i in opt.arguments: if i.startswith(('--load-extension=', '--remote-debugging-port=')): continue elif i.startswith('--user-data-dir') and not opt.system_user_path: - p = Path(i[16:]).absolute() - result.add(f'--user-data-dir={p}') + result.add(f'--user-data-dir={Path(i[16:]).absolute()}') has_user_path = True + continue + elif i.startswith('--remote-allow-origins='): + remote_allow = True + result.add(i) if not has_user_path and not opt.system_user_path: @@ -78,6 +82,9 @@ def get_launch_args(opt): path.mkdir(parents=True, exist_ok=True) result.add(f'--user-data-dir={path}') + if not remote_allow: + result.add('--remote-allow-origins=*') + result = list(result) # ----------处理插件extensions------------- @@ -164,6 +171,7 @@ def _run_browser(port, path: str, args) -> Popen: :param args: 启动参数 :return: 进程对象 """ + print(port) arguments = [path, f'--remote-debugging-port={port}'] arguments.extend(args) return Popen(arguments, shell=False)