mirror of https://github.com/jumpserver/jumpserver
perf: update chrome applets hang (#14353)
* perf: update chrome applets hang * perf: remove debug print --------- Co-authored-by: Eric <xplzv@126.com>pull/14373/head
parent
af91b6faeb
commit
d30de0b6a0
|
@ -1,3 +1,7 @@
|
||||||
|
#2024-10-24 Version 1.1
|
||||||
|
## 功能优化
|
||||||
|
- 优化快速点击造成页面卡住的问题
|
||||||
|
|
||||||
#2023-09-18 Version 1.0
|
#2023-09-18 Version 1.0
|
||||||
## Bug 修复
|
## Bug 修复
|
||||||
- 移除窗口最小化,避免造成部分页面元素定位失败
|
- 移除窗口最小化,避免造成部分页面元素定位失败
|
||||||
|
|
|
@ -228,6 +228,8 @@ def default_chrome_driver_options():
|
||||||
"profile.password_manager_enabled": False
|
"profile.password_manager_enabled": False
|
||||||
}
|
}
|
||||||
options.add_experimental_option("prefs", prefs)
|
options.add_experimental_option("prefs", prefs)
|
||||||
|
# chromedriver 退出后也不关闭浏览器
|
||||||
|
options.add_experimental_option("detach", True)
|
||||||
options.add_experimental_option("excludeSwitches", ['enable-automation'])
|
options.add_experimental_option("excludeSwitches", ['enable-automation'])
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
@ -237,6 +239,7 @@ class AppletApplication(BaseApplication):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.driver = None
|
self.driver = None
|
||||||
|
self.service = None
|
||||||
self.app = WebAPP(app_name=self.app_name, user=self.user,
|
self.app = WebAPP(app_name=self.app_name, user=self.user,
|
||||||
account=self.account, asset=self.asset, platform=self.platform)
|
account=self.account, asset=self.asset, platform=self.platform)
|
||||||
self._tmp_user_dir = tempfile.TemporaryDirectory()
|
self._tmp_user_dir = tempfile.TemporaryDirectory()
|
||||||
|
@ -251,10 +254,10 @@ class AppletApplication(BaseApplication):
|
||||||
|
|
||||||
@wrapper_progress_bar
|
@wrapper_progress_bar
|
||||||
def run(self):
|
def run(self):
|
||||||
service = Service()
|
self.service = Service()
|
||||||
# driver 的 console 终端框不显示
|
# driver 的 console 终端框不显示
|
||||||
service.creationflags = CREATE_NO_WINDOW
|
self.service.creationflags = CREATE_NO_WINDOW
|
||||||
self.driver = webdriver.Chrome(options=self._chrome_options, service=service)
|
self.driver = webdriver.Chrome(options=self._chrome_options, service=self.service)
|
||||||
self.driver.implicitly_wait(10)
|
self.driver.implicitly_wait(10)
|
||||||
if self.app.asset.address != "":
|
if self.app.asset.address != "":
|
||||||
ok = self.app.execute(self.driver)
|
ok = self.app.execute(self.driver)
|
||||||
|
@ -263,21 +266,19 @@ class AppletApplication(BaseApplication):
|
||||||
self.driver.maximize_window()
|
self.driver.maximize_window()
|
||||||
|
|
||||||
def wait(self):
|
def wait(self):
|
||||||
disconnected_msg = "Unable to evaluate script: disconnected: not connected to DevTools\n"
|
from common import check_pid_alive
|
||||||
closed_msg = "Unable to evaluate script: no such window: target window already closed"
|
parent_id = self.service.process.pid
|
||||||
|
pids = get_children_pids(parent_id)
|
||||||
|
pids_status = {pid: True for pid in pids}
|
||||||
|
# 退出 chromedriver 进程,等待所有子进程退出
|
||||||
|
self.service.stop()
|
||||||
while True:
|
while True:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
logs = self.driver.get_log('driver')
|
for pid in pids_status:
|
||||||
if len(logs) == 0:
|
pids_status[pid] = check_pid_alive(pid)
|
||||||
continue
|
status = any(pids_status.values())
|
||||||
ret = logs[-1]
|
if not status:
|
||||||
if isinstance(ret, dict):
|
break
|
||||||
message = ret.get('message', '')
|
|
||||||
if disconnected_msg in message or closed_msg in message:
|
|
||||||
break
|
|
||||||
print("ret: ", ret)
|
|
||||||
self.close()
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if self.driver:
|
if self.driver:
|
||||||
|
@ -290,3 +291,23 @@ class AppletApplication(BaseApplication):
|
||||||
self._tmp_user_dir.cleanup()
|
self._tmp_user_dir.cleanup()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
|
def get_children_pids(parent_pid):
|
||||||
|
import subprocess
|
||||||
|
from common import decode_content
|
||||||
|
pids = []
|
||||||
|
# wmic process where (ParentProcessId={5088}) get ProcessId
|
||||||
|
try:
|
||||||
|
cmd = ['wmic', 'process', 'where', f'(ParentProcessId={parent_pid})', 'get', 'ProcessId']
|
||||||
|
ret = subprocess.check_output(cmd, creationflags=CREATE_NO_WINDOW)
|
||||||
|
content = decode_content(ret)
|
||||||
|
content_list = content.strip().split("\r\n")
|
||||||
|
for pid in content_list[1:]:
|
||||||
|
pid = pid.strip()
|
||||||
|
if pid:
|
||||||
|
pids.append(int(pid))
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
return pids
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: chrome
|
name: chrome
|
||||||
display_name: "{{ 'Chrome Browser' | trans }}"
|
display_name: "{{ 'Chrome Browser' | trans }}"
|
||||||
version: 1.0
|
version: 1.1
|
||||||
comment: "{{ 'Chrome Browser Open URL Page Address' | trans }}"
|
comment: "{{ 'Chrome Browser Open URL Page Address' | trans }}"
|
||||||
author: JumpServer Team
|
author: JumpServer Team
|
||||||
exec_type: python
|
exec_type: python
|
||||||
|
|
Loading…
Reference in New Issue