4.1.0.5修复window.show()问题;修复判断无痕模式不准确问题;Chromium的states为属性

This commit is contained in:
g1879 2024-09-23 16:39:56 +08:00
parent 89c5dfbacf
commit cebee0a720
7 changed files with 20 additions and 9 deletions

View File

@ -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'

View File

@ -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:

View File

@ -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)

View File

@ -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
"""

View File

@ -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:

View File

@ -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

View File

@ -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:
"""返回浏览器是否无痕模式"""
...