mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
3.1.4修复标签页关闭时页面发起请求导致的问题
This commit is contained in:
parent
43d0a742d1
commit
b03e919989
@ -93,7 +93,11 @@ class ChromiumBase(BasePage):
|
|||||||
if self._debug_recorder:
|
if self._debug_recorder:
|
||||||
self._debug_recorder.add_data((perf_counter(), '获取document', '开始'))
|
self._debug_recorder.add_data((perf_counter(), '获取document', '开始'))
|
||||||
|
|
||||||
self._wait_loaded()
|
try: # 处理标签页关闭的情况
|
||||||
|
self._wait_loaded()
|
||||||
|
except ConnectionError:
|
||||||
|
return
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
root_id = self._tab_obj.DOM.getDocument()['root']['nodeId']
|
root_id = self._tab_obj.DOM.getDocument()['root']['nodeId']
|
||||||
@ -251,7 +255,10 @@ class ChromiumBase(BasePage):
|
|||||||
@property
|
@property
|
||||||
def ready_state(self):
|
def ready_state(self):
|
||||||
"""返回当前页面加载状态,'loading' 'interactive' 'complete'"""
|
"""返回当前页面加载状态,'loading' 'interactive' 'complete'"""
|
||||||
return self._tab_obj.Runtime.evaluate(expression='document.readyState;')['result']['value']
|
try:
|
||||||
|
return self._tab_obj.Runtime.evaluate(expression='document.readyState;')['result']['value']
|
||||||
|
except KeyError:
|
||||||
|
raise ConnectionError('标签页或连接已关闭。')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def size(self):
|
def size(self):
|
||||||
|
@ -146,8 +146,9 @@ class ChromiumDriver(object):
|
|||||||
if event['method'] in self.event_handlers:
|
if event['method'] in self.event_handlers:
|
||||||
try:
|
try:
|
||||||
self.event_handlers[event['method']](**event['params'])
|
self.event_handlers[event['method']](**event['params'])
|
||||||
except Exception as e:
|
except Exception:
|
||||||
raise RuntimeError(f"回调函数 {event['method']} 错误:{e}")
|
pass
|
||||||
|
# raise RuntimeError(f"回调函数 {event['method']} 错误:{e}")
|
||||||
|
|
||||||
self.event_queue.task_done()
|
self.event_queue.task_done()
|
||||||
|
|
||||||
@ -169,10 +170,12 @@ class ChromiumDriver(object):
|
|||||||
raise CallMethodException("参数必须是key=value形式。")
|
raise CallMethodException("参数必须是key=value形式。")
|
||||||
|
|
||||||
if self._stopped.is_set():
|
if self._stopped.is_set():
|
||||||
raise RuntimeError("Driver已经停止。")
|
return {'tab_closed': True}
|
||||||
|
|
||||||
timeout = kwargs.pop("_timeout", None)
|
timeout = kwargs.pop("_timeout", None)
|
||||||
result = self._send({"method": _method, "params": kwargs}, timeout=timeout)
|
result = self._send({"method": _method, "params": kwargs}, timeout=timeout)
|
||||||
|
if result is None:
|
||||||
|
return {'tab_closed': True}
|
||||||
if 'result' not in result and 'error' in result:
|
if 'result' not in result and 'error' in result:
|
||||||
raise CallMethodException(f"\n调用方法:{_method}\n参数:{kwargs}\n错误:{result['error']['message']}")
|
raise CallMethodException(f"\n调用方法:{_method}\n参数:{kwargs}\n错误:{result['error']['message']}")
|
||||||
|
|
||||||
@ -204,6 +207,9 @@ class ChromiumDriver(object):
|
|||||||
self._stopped.set()
|
self._stopped.set()
|
||||||
if self._ws:
|
if self._ws:
|
||||||
self._ws.close()
|
self._ws.close()
|
||||||
|
self.event_handlers = {}
|
||||||
|
self.method_results = {}
|
||||||
|
self.event_queue = Queue()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def set_listener(self, event, callback):
|
def set_listener(self, event, callback):
|
||||||
|
2
setup.py
2
setup.py
@ -6,7 +6,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="DrissionPage",
|
name="DrissionPage",
|
||||||
version="3.1.3",
|
version="3.1.4",
|
||||||
author="g1879",
|
author="g1879",
|
||||||
author_email="g1879@qq.com",
|
author_email="g1879@qq.com",
|
||||||
description="A module that integrates selenium and requests session, encapsulates common page operations.",
|
description="A module that integrates selenium and requests session, encapsulates common page operations.",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user