zhepama commited on
Commit
d453417
·
verified ·
1 Parent(s): c511203

Update src/index.ts

Browse files
Files changed (1) hide show
  1. src/index.ts +71 -12
src/index.ts CHANGED
@@ -35,18 +35,18 @@ async function initGensparkPage(cookies?: any[]) {
35
 
36
  if (!gensparkContext) {
37
  gensparkContext = await browser.newContext({
38
- userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
39
- viewport: { width: 1920, height: 1080 },
40
- deviceScaleFactor: 1,
41
- hasTouch: false,
42
- locale: 'en-US',
43
- timezoneId: 'America/New_York',
44
- geolocation: { longitude: -73.935242, latitude: 40.730610 }, // 纽约坐标,可根据需要调整
45
- permissions: ['geolocation'],
46
- javaScriptEnabled: true,
47
- bypassCSP: true, // 绕过内容安全策略
48
- colorScheme: 'light',
49
- acceptDownloads: true,
50
  })
51
  }
52
  if (cookies && cookies.length > 0) {
@@ -54,6 +54,65 @@ async function initGensparkPage(cookies?: any[]) {
54
  }
55
  if (!gensparkPage) {
56
  gensparkPage = await gensparkContext.newPage()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  // 首次加载页面
58
  await gensparkPage.goto('https://www.genspark.ai', {
59
  waitUntil: 'networkidle',
 
35
 
36
  if (!gensparkContext) {
37
  gensparkContext = await browser.newContext({
38
+ userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
39
+ viewport: { width: 1920, height: 1080 },
40
+ deviceScaleFactor: 1,
41
+ hasTouch: false,
42
+ locale: 'en-US',
43
+ timezoneId: 'America/New_York',
44
+ geolocation: { longitude: -73.935242, latitude: 40.730610 }, // 纽约坐标,可根据需要调整
45
+ permissions: ['geolocation'],
46
+ javaScriptEnabled: true,
47
+ bypassCSP: true, // 绕过内容安全策略
48
+ colorScheme: 'light',
49
+ acceptDownloads: true,
50
  })
51
  }
52
  if (cookies && cookies.length > 0) {
 
54
  }
55
  if (!gensparkPage) {
56
  gensparkPage = await gensparkContext.newPage()
57
+
58
+ // 修改 webdriver 和 navigator 属性以避免自动化检测
59
+ await gensparkPage.addInitScript(() => {
60
+ // 覆盖 webdriver 属性
61
+ Object.defineProperty(navigator, 'webdriver', {
62
+ get: () => false,
63
+ });
64
+
65
+ // 修改 user-agent 中的 HeadlessChrome 字符串
66
+ const userAgent = navigator.userAgent;
67
+ if (userAgent.includes('HeadlessChrome')) {
68
+ Object.defineProperty(navigator, 'userAgent', {
69
+ get: () => userAgent.replace('HeadlessChrome', 'Chrome'),
70
+ });
71
+ }
72
+
73
+ // 添加语言和插件,使其看起来更像真实浏览器
74
+ Object.defineProperty(navigator, 'languages', {
75
+ get: () => ['en-US', 'en', 'zh-CN'],
76
+ });
77
+
78
+ // 添加假的插件信息
79
+ Object.defineProperty(navigator, 'plugins', {
80
+ get: () => {
81
+ return [
82
+ {
83
+ description: "Portable Document Format",
84
+ filename: "internal-pdf-viewer",
85
+ name: "Chrome PDF Plugin"
86
+ },
87
+ {
88
+ description: "Portable Document Format",
89
+ filename: "mhjfbmdgcfjbbpaeojofohoefgiehjai",
90
+ name: "Chrome PDF Viewer"
91
+ },
92
+ {
93
+ description: "Widevine Content Decryption Module",
94
+ filename: "widevinecdmadapter.dll",
95
+ name: "Widevine Content Decryption Module"
96
+ }
97
+ ];
98
+ },
99
+ });
100
+
101
+ // 创建假的 WebGL 渲染器信息
102
+ const getParameter = WebGLRenderingContext.prototype.getParameter;
103
+ WebGLRenderingContext.prototype.getParameter = function (parameter) {
104
+ // UNMASKED_VENDOR_WEBGL
105
+ if (parameter === 37445) {
106
+ return 'Intel Inc.';
107
+ }
108
+ // UNMASKED_RENDERER_WEBGL
109
+ if (parameter === 37446) {
110
+ return 'Intel Iris OpenGL Engine';
111
+ }
112
+ return getParameter.call(this, parameter);
113
+ };
114
+ });
115
+
116
  // 首次加载页面
117
  await gensparkPage.goto('https://www.genspark.ai', {
118
  waitUntil: 'networkidle',