修复browser的一些问题

This commit is contained in:
g1879 2023-11-05 23:05:27 +08:00
parent 9331721b44
commit 99dfaf91da
3 changed files with 16 additions and 8 deletions

View File

@ -47,16 +47,15 @@ class Browser(object):
self._process_id = i['id'] self._process_id = i['id']
break break
self.run_cdp('Target.setDiscoverTargets') self.run_cdp('Target.setDiscoverTargets', discover=True)
self._driver.set_listener('Target.targetDestroyed', self._onTargetDestroyed) self._driver.set_listener('Target.targetDestroyed', self._onTargetDestroyed)
def _onTargetDestroyed(self, **kwargs): def _onTargetDestroyed(self, **kwargs):
"""标签页关闭时执行""" """标签页关闭时执行"""
tab_id = kwargs['targetId'] tab_id = kwargs['targetId']
self._dl_mgr.clear_tab_info(tab_id) self._dl_mgr.clear_tab_info(tab_id)
for k, i in self._frames.items(): for item in [(k, i) for k, i in self._frames.items() if i == tab_id]:
if i == tab_id: self._frames.pop(item[0])
self._frames.pop(k)
def connect_to_page(self): def connect_to_page(self):
"""执行与page相关的逻辑""" """执行与page相关的逻辑"""

View File

@ -50,6 +50,6 @@ class Browser(object):
def connect_to_page(self) -> None: ... def connect_to_page(self) -> None: ...
def _onTargetDestroyed(self, **kwargs): ... def _onTargetDestroyed(self, **kwargs) -> None: ...
def quit(self) -> None: ... def quit(self) -> None: ...

View File

@ -127,9 +127,18 @@ class BrowserDownloadManager(object):
:param tab_id: 标签页id :param tab_id: 标签页id
:return: None :return: None
""" """
self._tab_missions.pop(tab_id) try:
self._flags.pop(tab_id) self._tab_missions.pop(tab_id)
TabDownloadSettings.TABS.pop(tab_id) except KeyError:
pass
try:
self._flags.pop(tab_id)
except KeyError:
pass
try:
TabDownloadSettings.TABS.pop(tab_id)
except KeyError:
pass
def _onDownloadWillBegin(self, **kwargs): def _onDownloadWillBegin(self, **kwargs):
"""用于获取弹出新标签页触发的下载任务""" """用于获取弹出新标签页触发的下载任务"""