修复set_flags的一个问题;修改quit()逻辑

This commit is contained in:
g1879 2024-03-12 23:41:45 +08:00
parent 2157fcf9e3
commit 4a9ef7d6b2
6 changed files with 27 additions and 20 deletions

View File

@ -203,24 +203,31 @@ class Browser(object):
:param force: 是否立刻强制终止进程
:return: None
"""
pids = [pid['id'] for pid in self.run_cdp('SystemInfo.getProcessInfo')['processInfo']]
for tab in self._all_drivers.values():
try:
self.run_cdp('Browser.close')
except PageDisconnectedError:
pass
self.driver.stop()
drivers = list(self._all_drivers.values())
for tab in drivers:
for driver in tab:
driver.stop()
if force:
from psutil import Process
for pid in pids:
try:
Process(pid).kill()
except:
pass
else:
if not force:
return
try:
pids = [pid['id'] for pid in self.run_cdp('SystemInfo.getProcessInfo')['processInfo']]
except:
return
from psutil import Process
for pid in pids:
try:
self.run_cdp('Browser.close')
self.driver.stop()
except PageDisconnectedError:
self.driver.stop()
Process(pid).kill()
except:
pass
from os import popen
from platform import system

View File

@ -176,8 +176,8 @@ def set_flags(opt):
states_dict = load(f)
except JSONDecodeError:
states_dict = {}
flags_list = [] if opt.clear_file_flags else states_dict.setdefault(
'browser', {}).setdefault('enabled_labs_experiments', [])
states_dict.setdefault('browser', {}).setdefault('enabled_labs_experiments', [])
flags_list = [] if opt.clear_file_flags else states_dict['browser']['enabled_labs_experiments']
flags_dict = {}
for i in flags_list:
f = str(i).split('@', 1)

View File

@ -474,7 +474,7 @@ class ChromiumBase(BasePage):
def cookies(self, as_dict=False, all_domains=False, all_info=False):
"""返回cookies信息
:param as_dict: 为True时返回由{name: value}键值对组成的dict为True时返回list且all_info无效
:param as_dict: 为True时以dict格式返回为False时返回list且all_info无效
:param all_domains: 是否返回所有域的cookies
:param all_info: 是否返回所有信息为False时只返回namevaluedomain
:return: cookies信息

View File

@ -363,7 +363,7 @@ class WebPageTab(SessionPage, ChromiumTab, BasePage):
def cookies(self, as_dict=False, all_domains=False, all_info=False):
"""返回cookies
:param as_dict: 是否以字典方式返回
:param as_dict: 为True时以dict格式返回为False时返回list且all_info无效
:param all_domains: 是否返回所有域的cookies
:param all_info: 是否返回所有信息False则只返回namevaluedomain
:return: cookies信息

View File

@ -221,7 +221,7 @@ class SessionPage(BasePage):
def cookies(self, as_dict=False, all_domains=False, all_info=False):
"""返回cookies
:param as_dict: 是否以字典方式返回False则以list返回
:param as_dict: 为True时以dict格式返回为False时返回list且all_info无效
:param all_domains: 是否返回所有域的cookies
:param all_info: 是否返回所有信息False则只返回namevaluedomain
:return: cookies信息

View File

@ -298,7 +298,7 @@ class WebPage(SessionPage, ChromiumPage, BasePage):
def cookies(self, as_dict=False, all_domains=False, all_info=False):
"""返回cookies
:param as_dict: 是否以字典方式返回False以list形式返回
:param as_dict: 为True时以dict格式返回为False时返回list且all_info无效
:param all_domains: 是否返回所有域的cookies
:param all_info: 是否返回所有信息False则只返回namevaluedomain
:return: cookies信息