Spaces:
Sleeping
Sleeping
Update src/index.ts
Browse files- src/index.ts +88 -5
src/index.ts
CHANGED
@@ -19,9 +19,17 @@ async function initBrowser() {
|
|
19 |
browser = await chromium.launch({
|
20 |
headless: true,
|
21 |
args: [
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
],
|
26 |
executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH, // 使用系统 Chromium
|
27 |
})
|
@@ -35,8 +43,25 @@ async function initGensparkPage(cookies?: any[]) {
|
|
35 |
|
36 |
if (!gensparkContext) {
|
37 |
gensparkContext = await browser.newContext({
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
})
|
41 |
}
|
42 |
if (cookies && cookies.length > 0) {
|
@@ -49,6 +74,64 @@ async function initGensparkPage(cookies?: any[]) {
|
|
49 |
waitUntil: 'networkidle',
|
50 |
timeout: 60000
|
51 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
console.log('GenSpark页面已初始化')
|
53 |
}
|
54 |
return gensparkPage
|
|
|
19 |
browser = await chromium.launch({
|
20 |
headless: true,
|
21 |
args: [
|
22 |
+
'--no-sandbox',
|
23 |
+
'--disable-setuid-sandbox',
|
24 |
+
'--disable-dev-shm-usage',
|
25 |
+
'--disable-blink-features=AutomationControlled',
|
26 |
+
'--disable-features=IsolateOrigins,site-per-process',
|
27 |
+
'--disable-web-security',
|
28 |
+
'--disable-site-isolation-trials',
|
29 |
+
'--ignore-certificate-errors',
|
30 |
+
'--window-size=1920,1080',
|
31 |
+
'--start-maximized',
|
32 |
+
'--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36'
|
33 |
],
|
34 |
executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH, // 使用系统 Chromium
|
35 |
})
|
|
|
43 |
|
44 |
if (!gensparkContext) {
|
45 |
gensparkContext = await browser.newContext({
|
46 |
+
viewport: { width: 1920, height: 1080 },
|
47 |
+
deviceScaleFactor: 1,
|
48 |
+
hasTouch: false,
|
49 |
+
javaScriptEnabled: true,
|
50 |
+
locale: 'en-US',
|
51 |
+
timezoneId: 'America/New_York',
|
52 |
+
geolocation: { longitude: -74.006, latitude: 40.7128 }, // New York coordinates
|
53 |
+
permissions: ['geolocation'],
|
54 |
+
colorScheme: 'light',
|
55 |
+
reducedMotion: 'no-preference',
|
56 |
+
forcedColors: 'none',
|
57 |
+
acceptDownloads: true,
|
58 |
+
ignoreHTTPSErrors: true,
|
59 |
+
bypassCSP: true,
|
60 |
+
extraHTTPHeaders: {
|
61 |
+
'Accept-Language': 'en-US,en;q=0.9',
|
62 |
+
'DNT': '1',
|
63 |
+
'Upgrade-Insecure-Requests': '1',
|
64 |
+
}
|
65 |
})
|
66 |
}
|
67 |
if (cookies && cookies.length > 0) {
|
|
|
74 |
waitUntil: 'networkidle',
|
75 |
timeout: 60000
|
76 |
})
|
77 |
+
|
78 |
+
// Override specific browser properties to avoid detection
|
79 |
+
await gensparkPage.addInitScript(() => {
|
80 |
+
// Override the navigator properties
|
81 |
+
Object.defineProperty(navigator, 'webdriver', { get: () => false });
|
82 |
+
Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3, 4, 5] });
|
83 |
+
Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'] });
|
84 |
+
|
85 |
+
// Add fake web audio and canvas fingerprints
|
86 |
+
const originalGetImageData = CanvasRenderingContext2D.prototype.getImageData;
|
87 |
+
CanvasRenderingContext2D.prototype.getImageData = function(x, y, w, h) {
|
88 |
+
const imageData = originalGetImageData.call(this, x, y, w, h);
|
89 |
+
// Add some noise to the canvas data
|
90 |
+
for (let i = 0; i < imageData.data.length; i += 4) {
|
91 |
+
imageData.data[i] = imageData.data[i] + Math.floor(Math.random() * 5);
|
92 |
+
imageData.data[i+1] = imageData.data[i+1] + Math.floor(Math.random() * 5);
|
93 |
+
imageData.data[i+2] = imageData.data[i+2] + Math.floor(Math.random() * 5);
|
94 |
+
}
|
95 |
+
return imageData;
|
96 |
+
};
|
97 |
+
|
98 |
+
// Override Chrome-specific properties
|
99 |
+
window.chrome = {
|
100 |
+
runtime: {},
|
101 |
+
loadTimes: function() {},
|
102 |
+
csi: function() {},
|
103 |
+
app: {}
|
104 |
+
};
|
105 |
+
|
106 |
+
// Spoof notification permissions
|
107 |
+
if (navigator.permissions) {
|
108 |
+
const originalQuery = navigator.permissions.query;
|
109 |
+
navigator.permissions.query = function(parameters) {
|
110 |
+
if (parameters.name === 'notifications') {
|
111 |
+
return Promise.resolve({ state: Notification.permission });
|
112 |
+
}
|
113 |
+
return originalQuery.call(this, parameters);
|
114 |
+
};
|
115 |
+
}
|
116 |
+
});
|
117 |
+
// Simulate human-like behavior
|
118 |
+
await gensparkPage.addInitScript(() => {
|
119 |
+
// Add random mouse movements
|
120 |
+
let lastMove = Date.now();
|
121 |
+
document.addEventListener('mousemove', function() {
|
122 |
+
lastMove = Date.now();
|
123 |
+
}, true);
|
124 |
+
|
125 |
+
// Simulate scroll behavior
|
126 |
+
window.addEventListener('scroll', function() {
|
127 |
+
// Random scroll speed
|
128 |
+
const scrollSpeed = Math.floor(Math.random() * 10) + 5;
|
129 |
+
const scrollAmount = Math.floor(Math.random() * 100);
|
130 |
+
setTimeout(() => {
|
131 |
+
window.scrollBy(0, scrollAmount);
|
132 |
+
}, scrollSpeed);
|
133 |
+
}, true);
|
134 |
+
});
|
135 |
console.log('GenSpark页面已初始化')
|
136 |
}
|
137 |
return gensparkPage
|