diff --git a/DrissionPage/__init__.py b/DrissionPage/__init__.py index d4d0162..37b3836 100644 --- a/DrissionPage/__init__.py +++ b/DrissionPage/__init__.py @@ -12,4 +12,4 @@ from ._pages.chromium_page import ChromiumPage from ._pages.session_page import SessionPage from ._pages.web_page import WebPage -__version__ = '4.1.0.4' +__version__ = '4.1.0.5' diff --git a/DrissionPage/_base/chromium.py b/DrissionPage/_base/chromium.py index 3eeb268..70a054a 100644 --- a/DrissionPage/_base/chromium.py +++ b/DrissionPage/_base/chromium.py @@ -307,7 +307,7 @@ class Chromium(object): if tab: kwargs['browserContextId'] = tab - if self.states.is_incognito(): + if self.states.is_incognito: return _new_tab_by_js(self, url, obj, new_window) else: try: diff --git a/DrissionPage/_functions/tools.py b/DrissionPage/_functions/tools.py index 92183d3..e99a62c 100644 --- a/DrissionPage/_functions/tools.py +++ b/DrissionPage/_functions/tools.py @@ -80,8 +80,8 @@ def clean_folder(folder_path, ignore=None): rmtree(f, True) -def show_or_hide_browser(page, hide=True): - if not page.browser.address.startswith(('127.0.0.1', 'localhost')): +def show_or_hide_browser(tab, hide=True): + if not tab.browser.address.startswith(('127.0.0.1', 'localhost')): return if system().lower() != 'windows': @@ -93,10 +93,10 @@ def show_or_hide_browser(page, hide=True): except ImportError: raise ImportError('请先安装:pip install pypiwin32') - pid = page._page.process_id + pid = tab.browser.process_id if not pid: return None - hds = get_hwnds_from_pid(pid, page.title) + hds = get_hwnds_from_pid(pid, tab.title) sw = SW_HIDE if hide else SW_SHOW for hd in hds: ShowWindow(hd, sw) diff --git a/DrissionPage/_functions/tools.pyi b/DrissionPage/_functions/tools.pyi index 8a7c3c8..2623bd8 100644 --- a/DrissionPage/_functions/tools.pyi +++ b/DrissionPage/_functions/tools.pyi @@ -53,9 +53,9 @@ def clean_folder(folder_path: Union[str, Path], ignore: Union[tuple, list] = Non ... -def show_or_hide_browser(page: ChromiumBase, hide: bool = True) -> None: +def show_or_hide_browser(tab: ChromiumBase, hide: bool = True) -> None: """执行显示或隐藏浏览器窗口 - :param page: ChromePage对象 + :param tab: ChromiumTab对象 :param hide: 是否隐藏 :return: None """ diff --git a/DrissionPage/_units/setter.pyi b/DrissionPage/_units/setter.pyi index b2890b9..b1f9e97 100644 --- a/DrissionPage/_units/setter.pyi +++ b/DrissionPage/_units/setter.pyi @@ -243,6 +243,9 @@ class BrowserSetter(BrowserBaseSetter): """返回用于设置cookies的对象""" ... + @property + def window(self)->WindowSetter:... + def auto_handle_alert(self, on_off: bool = True, accept: bool = True) -> None: diff --git a/DrissionPage/_units/states.py b/DrissionPage/_units/states.py index 7cff31c..456fa40 100644 --- a/DrissionPage/_units/states.py +++ b/DrissionPage/_units/states.py @@ -94,18 +94,22 @@ class BrowserStates(object): self._browser = browser self._incognito = None + @property def is_alive(self): return self._browser._driver.is_running + @property def is_headless(self): return self._browser._is_headless + @property def is_existed(self): return self._browser._is_exists + @property def is_incognito(self): if self._incognito is None: - self._incognito = str(self._browser._run_cdp('Browser.getHistograms')).count('Incognito') > 1 + self._incognito = "'Browser.WindowCount.Incognito'" in str(self._browser._run_cdp('Browser.getHistograms')) return self._incognito diff --git a/DrissionPage/_units/states.pyi b/DrissionPage/_units/states.pyi index dcf4fe9..f31463c 100644 --- a/DrissionPage/_units/states.pyi +++ b/DrissionPage/_units/states.pyi @@ -103,18 +103,22 @@ class BrowserStates(object): """ ... + @property def is_alive(self) -> bool: """返回浏览器是否仍可用""" ... + @property def is_headless(self) -> bool: """返回浏览器是否无头模式""" ... + @property def is_existed(self) -> bool: """返回浏览器是否接管的""" ... + @property def is_incognito(self) -> bool: """返回浏览器是否无痕模式""" ...