Spaces:
Sleeping
Sleeping
github-actions[bot]
commited on
Commit
·
d9a3952
1
Parent(s):
24965e4
Update from GitHub Actions
Browse files- src/index.ts +43 -3
src/index.ts
CHANGED
@@ -21,6 +21,9 @@ async function initBrowser() {
|
|
21 |
'--no-sandbox',
|
22 |
'--disable-setuid-sandbox',
|
23 |
'--disable-dev-shm-usage',
|
|
|
|
|
|
|
24 |
],
|
25 |
executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH, // 使用系统 Chromium
|
26 |
})
|
@@ -36,9 +39,10 @@ async function initGensparkContext() {
|
|
36 |
gensparkContext = await browser.newContext({
|
37 |
userAgent: userAgent,
|
38 |
viewport: { width: 1920, height: 1080 },
|
|
|
|
|
|
|
39 |
deviceScaleFactor: 1,
|
40 |
-
isMobile: true,
|
41 |
-
hasTouch: true,
|
42 |
locale: 'en-US',
|
43 |
timezoneId: 'America/New_York',
|
44 |
geolocation: { longitude: -73.935242, latitude: 40.730610 }, // 纽约坐标,可根据需要调整
|
@@ -48,6 +52,15 @@ async function initGensparkContext() {
|
|
48 |
colorScheme: 'light',
|
49 |
acceptDownloads: true,
|
50 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
|
53 |
return gensparkContext
|
@@ -198,12 +211,39 @@ app.get('/genspark', async (c) => {
|
|
198 |
await new Promise(resolve => setTimeout(resolve, 1000));
|
199 |
const gensparkPage = await gensparkContext.newPage()
|
200 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
//刷新页面以确保获取新令牌
|
202 |
await gensparkPage.goto('https://www.genspark.ai/agents?type=moa_chat', {
|
203 |
waitUntil: 'networkidle',
|
204 |
timeout: 3600000
|
205 |
})
|
206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
// 执行脚本获取令牌
|
208 |
const token = await gensparkPage.evaluate(() => {
|
209 |
return new Promise((resolve, reject) => {
|
|
|
21 |
'--no-sandbox',
|
22 |
'--disable-setuid-sandbox',
|
23 |
'--disable-dev-shm-usage',
|
24 |
+
'--disable-blink-features=AutomationControlled', // 禁用自动化特征
|
25 |
+
'--disable-infobars',
|
26 |
+
'--window-size=1920,1080'
|
27 |
],
|
28 |
executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH, // 使用系统 Chromium
|
29 |
})
|
|
|
39 |
gensparkContext = await browser.newContext({
|
40 |
userAgent: userAgent,
|
41 |
viewport: { width: 1920, height: 1080 },
|
42 |
+
extraHTTPHeaders: {
|
43 |
+
'Accept-Language': 'en-US,en;q=0.9'
|
44 |
+
},
|
45 |
deviceScaleFactor: 1,
|
|
|
|
|
46 |
locale: 'en-US',
|
47 |
timezoneId: 'America/New_York',
|
48 |
geolocation: { longitude: -73.935242, latitude: 40.730610 }, // 纽约坐标,可根据需要调整
|
|
|
52 |
colorScheme: 'light',
|
53 |
acceptDownloads: true,
|
54 |
})
|
55 |
+
|
56 |
+
// 注入反检测脚本
|
57 |
+
await gensparkContext.addInitScript(() => {
|
58 |
+
Object.defineProperty(navigator, 'webdriver', { get: () => false })
|
59 |
+
Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3, 4, 5] })
|
60 |
+
//@ts-ignore
|
61 |
+
window.navigator.chrome = { runtime: {} }
|
62 |
+
Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'] })
|
63 |
+
})
|
64 |
}
|
65 |
|
66 |
return gensparkContext
|
|
|
211 |
await new Promise(resolve => setTimeout(resolve, 1000));
|
212 |
const gensparkPage = await gensparkContext.newPage()
|
213 |
try {
|
214 |
+
// 模拟真实用户行为
|
215 |
+
await gensparkPage.route('**/*', (route) => {
|
216 |
+
return route.request().resourceType() === 'image'
|
217 |
+
? route.abort()
|
218 |
+
: route.continue()
|
219 |
+
})
|
220 |
+
|
221 |
//刷新页面以确保获取新令牌
|
222 |
await gensparkPage.goto('https://www.genspark.ai/agents?type=moa_chat', {
|
223 |
waitUntil: 'networkidle',
|
224 |
timeout: 3600000
|
225 |
})
|
226 |
+
|
227 |
+
// 等待并模拟人类交互
|
228 |
+
await gensparkPage.waitForTimeout(Math.random() * 2000 + 1000)
|
229 |
+
|
230 |
+
// 随机鼠标移动
|
231 |
+
await gensparkPage.mouse.move(
|
232 |
+
Math.random() * gensparkPage.viewportSize()!.width,
|
233 |
+
Math.random() * gensparkPage.viewportSize()!.height
|
234 |
+
)
|
235 |
+
await gensparkPage.waitForSelector('#recaptcha-anchor', { timeout: 10000 })
|
236 |
+
// 随机延迟点击
|
237 |
+
await gensparkPage.waitForTimeout(Math.random() * 1500 + 500)
|
238 |
+
// 模拟点击 reCAPTCHA
|
239 |
+
await gensparkPage.click('#recaptcha-anchor')
|
240 |
+
|
241 |
+
// 等待验证完成
|
242 |
+
await gensparkPage.waitForFunction(() => {
|
243 |
+
const checkbox = document.querySelector('#recaptcha-anchor')
|
244 |
+
return checkbox && checkbox.getAttribute('aria-checked') === 'true'
|
245 |
+
}, { timeout: 10000 })
|
246 |
+
|
247 |
// 执行脚本获取令牌
|
248 |
const token = await gensparkPage.evaluate(() => {
|
249 |
return new Promise((resolve, reject) => {
|