Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Pangea-Agent
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gavin-Group
Pangea-Agent
Commits
2a026455
Commit
2a026455
authored
Dec 30, 2025
by
王舵
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 监听browser连接断开,重新启动 browser
parent
a8007006
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
57 deletions
+77
-57
PlaywrightManagerImpl.java
...pangea/hiagent/tool/playwright/PlaywrightManagerImpl.java
+62
-48
application-dev.yml
backend/src/main/resources/application-dev.yml
+5
-5
vite.config.ts
frontend/vite.config.ts
+10
-4
No files found.
backend/src/main/java/pangea/hiagent/tool/playwright/PlaywrightManagerImpl.java
View file @
2a026455
...
@@ -31,8 +31,7 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
...
@@ -31,8 +31,7 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
private
static
final
long
CONTEXT_TIMEOUT
=
30
*
60
*
1000
;
private
static
final
long
CONTEXT_TIMEOUT
=
30
*
60
*
1000
;
// 清理任务调度器
// 清理任务调度器
private
final
ScheduledExecutorService
cleanupScheduler
=
private
final
ScheduledExecutorService
cleanupScheduler
=
Executors
.
newSingleThreadScheduledExecutor
(
r
->
{
Executors
.
newSingleThreadScheduledExecutor
(
r
->
{
Thread
t
=
new
Thread
(
r
,
"PlaywrightCleanupScheduler"
);
Thread
t
=
new
Thread
(
r
,
"PlaywrightCleanupScheduler"
);
t
.
setDaemon
(
true
);
// 设置为守护线程
t
.
setDaemon
(
true
);
// 设置为守护线程
return
t
;
return
t
;
...
@@ -66,6 +65,18 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
...
@@ -66,6 +65,18 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
"--disable-gpu"
,
"--disable-gpu"
,
"--remote-allow-origins=*"
)));
"--remote-allow-origins=*"
)));
this
.
browser
.
onDisconnected
((
browser
)
->
{
log
.
info
(
"浏览器实例已断开连接"
);
this
.
browser
.
close
();
this
.
browser
=
playwright
.
chromium
().
launch
(
new
BrowserType
.
LaunchOptions
()
.
setHeadless
(
true
)
.
setArgs
(
java
.
util
.
Arrays
.
asList
(
"--no-sandbox"
,
"--disable-dev-shm-usage"
,
"--disable-gpu"
,
"--remote-allow-origins=*"
)));
});
// 每5分钟检查一次超时的用户上下文
// 每5分钟检查一次超时的用户上下文
cleanupScheduler
.
scheduleAtFixedRate
(
this
::
cleanupExpiredContexts
,
cleanupScheduler
.
scheduleAtFixedRate
(
this
::
cleanupExpiredContexts
,
5
,
3600
,
TimeUnit
.
MINUTES
);
5
,
3600
,
TimeUnit
.
MINUTES
);
...
@@ -83,10 +94,10 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
...
@@ -83,10 +94,10 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
// 移除@PostConstruct注解,避免在Spring初始化时自动调用
// 移除@PostConstruct注解,避免在Spring初始化时自动调用
/*
/*
@PostConstruct
*
@PostConstruct
public void initialize() {
*
public void initialize() {
lazyInitialize();
*
lazyInitialize();
}
*
}
*/
*/
@Override
@Override
...
@@ -112,7 +123,10 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
...
@@ -112,7 +123,10 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
lazyInitialize
();
lazyInitialize
();
Browser
.
NewContextOptions
options
=
new
Browser
.
NewContextOptions
()
Browser
.
NewContextOptions
options
=
new
Browser
.
NewContextOptions
()
.
setViewportSize
(
1920
,
1080
)
// 设置视口大小为全高清分辨率,适用于Windows 11桌面环境
.
setViewportSize
(
1920
,
1080
)
// 设置视口大小为全高清分辨率,适用于Windows 11桌面环境
.
setUserAgent
(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
);
// 设置用户代理为Windows 11 Chrome浏览器
.
setUserAgent
(
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
);
// 设置用户代理为Windows
// 11
// Chrome浏览器
return
getUserContext
(
userId
,
options
);
return
getUserContext
(
userId
,
options
);
}
}
...
...
backend/src/main/resources/application-dev.yml
View file @
2a026455
...
@@ -2,10 +2,10 @@
...
@@ -2,10 +2,10 @@
spring
:
spring
:
# 开发环境数据源配置
# 开发环境数据源配置
datasource
:
datasource
:
url
:
jdbc:
h2:file:./data/hiagent_dev_db;DB_CLOSE_ON_EXIT=FALSE
url
:
jdbc:
mysql://${DB_HOST:127.0.0.1}:3306/hiagent?allowMultiQueries=true&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=Asia/Shanghai
driver-class-name
:
org.h2.Driver
driver-class-name
:
${DB_DRIVER:com.mysql.cj.jdbc.Driver}
username
:
sa
username
:
${DB_NAME:root}
password
:
sa
password
:
${DB_PASSWORD:password}
# 开发环境JPA配置
# 开发环境JPA配置
jpa
:
jpa
:
...
@@ -21,7 +21,7 @@ spring:
...
@@ -21,7 +21,7 @@ spring:
init
:
init
:
schema-locations
:
classpath:schema.sql
schema-locations
:
classpath:schema.sql
data-locations
:
classpath:data.sql
data-locations
:
classpath:data.sql
mode
:
always
# 总是执行创建表和数据脚本,实现重新初始化
mode
:
never
# 总是执行创建表和数据脚本,实现重新初始化
# 开启H2控制台
# 开启H2控制台
h2
:
h2
:
...
...
frontend/vite.config.ts
View file @
2a026455
/*
* @Date: 2025-12-29 14:42:27
* @LastEditors: wangduo3 wangduo3@hisense.com
* @LastEditTime: 2025-12-29 16:56:52
* @FilePath: /pangea-agent/frontend/vite.config.ts
*/
import
{
defineConfig
}
from
"vite"
;
import
{
defineConfig
}
from
"vite"
;
import
vue
from
"@vitejs/plugin-vue"
;
import
vue
from
"@vitejs/plugin-vue"
;
import
path
from
"path"
;
import
path
from
"path"
;
...
@@ -30,14 +36,14 @@ export default defineConfig({
...
@@ -30,14 +36,14 @@ export default defineConfig({
},
},
proxy
:
{
proxy
:
{
"/api"
:
{
"/api"
:
{
//
target: "http://localhost:8080",
target
:
"http://localhost:8080"
,
target
:
"http://agent-backend.clouddev.hisense.com"
,
//
target: "http://agent-backend.clouddev.hisense.com",
changeOrigin
:
true
,
changeOrigin
:
true
,
rewrite
:
(
path
)
=>
path
.
replace
(
/^
\/
api/
,
"/api"
),
rewrite
:
(
path
)
=>
path
.
replace
(
/^
\/
api/
,
"/api"
),
},
},
"/ws"
:
{
"/ws"
:
{
//
target: "http://localhost:8080",
target
:
"http://localhost:8080"
,
target
:
"http://agent-backend.clouddev.hisense.com"
,
//
target: "http://agent-backend.clouddev.hisense.com",
ws
:
true
,
// 启用WebSocket代理
ws
:
true
,
// 启用WebSocket代理
changeOrigin
:
true
,
changeOrigin
:
true
,
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment