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
f1c0112e
Commit
f1c0112e
authored
Dec 30, 2025
by
youxiaoji
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
* [playwright 初始化后不再初始化]
parent
488dd115
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
19 deletions
+22
-19
PlaywrightManagerImpl.java
...pangea/hiagent/tool/playwright/PlaywrightManagerImpl.java
+22
-19
No files found.
backend/src/main/java/pangea/hiagent/tool/playwright/PlaywrightManagerImpl.java
View file @
f1c0112e
...
@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
jakarta.annotation.PreDestroy
;
import
jakarta.annotation.PreDestroy
;
import
java.util.concurrent.*
;
import
java.util.concurrent.*
;
/**
/**
...
@@ -54,21 +55,11 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
...
@@ -54,21 +55,11 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
log
.
info
(
"正在初始化Playwright管理器..."
);
log
.
info
(
"正在初始化Playwright管理器..."
);
// 创建Playwright实例
// 创建Playwright实例
this
.
playwright
=
Playwright
.
create
();
if
(
playwright
==
null
)
{
this
.
playwright
=
Playwright
.
create
();
// 启动Chrome浏览器,无头模式
}
this
.
browser
=
playwright
.
chromium
().
launch
(
new
BrowserType
.
LaunchOptions
()
if
(
browser
==
null
)
{
.
setHeadless
(
true
)
// 启动Chrome浏览器,无头模式
.
setArgs
(
java
.
util
.
Arrays
.
asList
(
"--no-sandbox"
,
"--disable-dev-shm-usage"
,
"--disable-gpu"
,
"--remote-allow-origins=*"
)));
this
.
browser
.
onDisconnected
((
browser
)
->
{
log
.
info
(
"浏览器实例已断开连接"
);
this
.
browser
.
close
();
userContexts
.
clear
();
this
.
browser
=
playwright
.
chromium
().
launch
(
new
BrowserType
.
LaunchOptions
()
this
.
browser
=
playwright
.
chromium
().
launch
(
new
BrowserType
.
LaunchOptions
()
.
setHeadless
(
true
)
.
setHeadless
(
true
)
.
setArgs
(
java
.
util
.
Arrays
.
asList
(
.
setArgs
(
java
.
util
.
Arrays
.
asList
(
...
@@ -76,8 +67,20 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
...
@@ -76,8 +67,20 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
"--disable-dev-shm-usage"
,
"--disable-dev-shm-usage"
,
"--disable-gpu"
,
"--disable-gpu"
,
"--remote-allow-origins=*"
)));
"--remote-allow-origins=*"
)));
});
this
.
browser
.
onDisconnected
((
browser
)
->
{
log
.
info
(
"浏览器实例已断开连接"
);
this
.
browser
.
close
();
userContexts
.
clear
();
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
);
...
@@ -126,8 +129,8 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
...
@@ -126,8 +129,8 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
.
setViewportSize
(
1920
,
1080
)
// 设置视口大小为全高清分辨率,适用于Windows 11桌面环境
.
setViewportSize
(
1920
,
1080
)
// 设置视口大小为全高清分辨率,适用于Windows 11桌面环境
.
setUserAgent
(
.
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
"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
// 11
// Chrome浏览器
// Chrome浏览器
return
getUserContext
(
userId
,
options
);
return
getUserContext
(
userId
,
options
);
}
}
...
@@ -182,7 +185,7 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
...
@@ -182,7 +185,7 @@ public class PlaywrightManagerImpl implements PlaywrightManager {
/**
/**
* 检查BrowserContext是否已关闭
* 检查BrowserContext是否已关闭
*
*
* @param context 要检查的BrowserContext
* @param context 要检查的BrowserContext
* @return 如果上下文已关闭则返回true,否则返回false
* @return 如果上下文已关闭则返回true,否则返回false
*/
*/
...
...
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