From cae2151795dd2bfcb3362b2db044247fd6d2ed21 Mon Sep 17 00:00:00 2001 From: g1879 Date: Tue, 30 Jul 2024 17:59:14 +0800 Subject: [PATCH] =?UTF-8?q?4.1.0.0b17=E4=BF=AE=E5=A4=8D=E5=B0=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/__init__.py | 2 +- DrissionPage/_pages/chromium_base.py | 2 +- DrissionPage/_pages/chromium_frame.py | 19 +++++++++++-------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index a4ee172..59ac683 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -14,4 +14,4 @@ from ._pages.chromium_page import ChromiumPage from ._pages.mix_page import MixPage from ._pages.mix_page import MixPage as WebPage -__version__ = '4.1.0.0b16' +__version__ = '4.1.0.0b17' diff --git a/DrissionPage/_pages/chromium_base.py b/DrissionPage/_pages/chromium_base.py index f99dafb..770baf6 100644 --- a/DrissionPage/_pages/chromium_base.py +++ b/DrissionPage/_pages/chromium_base.py @@ -109,7 +109,7 @@ class ChromiumBase(BasePage): self._ready_state = 'complete' def _driver_init(self, target_id): - """新建页面、页面刷新、切换标签页后要进行的cdp参数初始化 + """新建页面、页面刷新后要进行的cdp参数初始化 :param target_id: 要跳转到的target id :return: None """ diff --git a/DrissionPage/_pages/chromium_frame.py b/DrissionPage/_pages/chromium_frame.py index 2a50d7f..fad9027 100644 --- a/DrissionPage/_pages/chromium_frame.py +++ b/DrissionPage/_pages/chromium_frame.py @@ -30,15 +30,15 @@ class ChromiumFrame(ChromiumBase): :param ele: frame所在元素 :param info: frame所在元素信息 """ - node = info['node'] if info else owner._run_cdp('DOM.describeNode', backendNodeId=ele._backend_id)['node'] - if Settings.singleton_tab_obj and node['frameId'] in cls._Frames: - r = cls._Frames[node['frameId']] - while not hasattr(r, '_frame_id'): + fid = info['node']['frameId'] if info else owner._run_cdp('DOM.describeNode', + backendNodeId=ele._backend_id)['node']['frameId'] + if Settings.singleton_tab_obj and fid in cls._Frames: + r = cls._Frames[fid] + while not hasattr(r, '_type') or r._type != 'ChromiumFrame': sleep(.1) return r r = object.__new__(cls) - r._frame_id = node['frameId'] - cls._Frames[node['frameId']] = r + cls._Frames[fid] = r return r def __init__(self, owner, ele, info=None): @@ -47,6 +47,10 @@ class ChromiumFrame(ChromiumBase): :param ele: frame所在元素 :param info: frame所在元素信息 """ + if Settings.singleton_tab_obj and hasattr(self, '_created'): + return + self._created = True + self._tab = owner._tab self._target_page = owner self._backend_id = ele._backend_id @@ -54,6 +58,7 @@ class ChromiumFrame(ChromiumBase): self._reloading = False node = info['node'] if info else owner._run_cdp('DOM.describeNode', backendNodeId=ele._backend_id)['node'] + self._frame_id = node['frameId'] if self._is_inner_frame(): self._is_diff_domain = False self.doc_ele = ChromiumElement(self._target_page, backend_id=node['contentDocument']['backendNodeId']) @@ -195,8 +200,6 @@ class ChromiumFrame(ChromiumBase): """同域变异域""" self.browser._frames.pop(kwargs['frameId'], None) ChromiumFrame._Frames.pop(kwargs['frameId'], None) - while not hasattr(self, '_frame_id'): - sleep(.1) if kwargs['frameId'] == self._frame_id: self._reload()