gemini-proxy-client 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -129,38 +129,97 @@ export class BrowserManager {
129
129
  if (!this.page)
130
130
  throw new Error('Browser not launched');
131
131
  // 等待页面完全加载
132
- await sleep(5000);
133
- // 尝试多种方式找到连接按钮
134
- const buttonSelectors = [
135
- 'button:has-text("Connect WS")', // 实际按钮文字
136
- 'button[aria-label="Connect WebSocket Proxy"]', // aria-label
137
- 'button[title="Connect WebSocket Proxy"]', // title 属性
138
- 'button:has-text("ws connect")',
139
- 'button:has-text("connect")',
140
- 'button.bg-green-500', // 绿色按钮
141
- ];
142
- let clicked = false;
143
- // 先尝试设置服务器地址 (如果有输入框)
132
+ await sleep(3000);
133
+ // 第一步:点击 "Continue to the app" 按钮(如果存在)
134
+ try {
135
+ const continueButton = await this.page.waitForSelector('button:has-text("Continue to the app")', { timeout: 5000 });
136
+ if (continueButton) {
137
+ await continueButton.click();
138
+ console.log(chalk.green('✅ 点击了 "Continue to the app" 按钮'));
139
+ await sleep(5000); // 等待页面切换,给更多时间
140
+ }
141
+ }
142
+ catch (e) {
143
+ // 按钮不存在,可能已经在 app 页面了
144
+ }
145
+ // 第二步:设置服务器地址(如果有输入框)
144
146
  await this.setServerAddress();
145
- for (const selector of buttonSelectors) {
147
+ // 第三步:点击 Connect WS 按钮
148
+ let clicked = false;
149
+ // 方法1: 通过 span 文字找到按钮
150
+ try {
151
+ const button = await this.page.waitForSelector('button span:has-text("Connect WS")', { timeout: 5000 });
152
+ if (button) {
153
+ // 点击父元素 button
154
+ await button.evaluate((el) => el.closest('button')?.click());
155
+ clicked = true;
156
+ console.log(chalk.green('✅ 点击了连接按钮'));
157
+ }
158
+ }
159
+ catch (e) {
160
+ // 继续尝试其他方法
161
+ }
162
+ // 方法2: 通过 aria-label
163
+ if (!clicked) {
146
164
  try {
147
- // 使用 waitForSelector 等待按钮出现
148
- const button = await this.page.waitForSelector(selector, { timeout: 3000 });
165
+ const button = await this.page.waitForSelector('button[aria-label="Connect WebSocket Proxy"]', { timeout: 3000 });
149
166
  if (button) {
150
167
  await button.click();
151
168
  clicked = true;
152
- console.log(chalk.green(`✅ 找到并点击了按钮: ${selector}`));
153
- break;
169
+ console.log(chalk.green('✅ 点击了连接按钮'));
170
+ }
171
+ }
172
+ catch (e) {
173
+ // 继续
174
+ }
175
+ }
176
+ // 方法3: 通过 title
177
+ if (!clicked) {
178
+ try {
179
+ const button = await this.page.waitForSelector('button[title="Connect WebSocket Proxy"]', { timeout: 3000 });
180
+ if (button) {
181
+ await button.click();
182
+ clicked = true;
183
+ console.log(chalk.green('✅ 点击了连接按钮'));
184
+ }
185
+ }
186
+ catch (e) {
187
+ // 继续
188
+ }
189
+ }
190
+ // 方法4: 通过绿色背景类名
191
+ if (!clicked) {
192
+ try {
193
+ const button = await this.page.waitForSelector('button.bg-green-500', { timeout: 3000 });
194
+ if (button) {
195
+ await button.click();
196
+ clicked = true;
197
+ console.log(chalk.green('✅ 点击了连接按钮'));
198
+ }
199
+ }
200
+ catch (e) {
201
+ // 继续
202
+ }
203
+ }
204
+ // 方法5: 通过 XPath 找包含 Connect WS 文字的按钮
205
+ if (!clicked) {
206
+ try {
207
+ const buttons = await this.page.$$('button');
208
+ for (const button of buttons) {
209
+ const text = await button.textContent();
210
+ if (text && text.includes('Connect WS')) {
211
+ await button.click();
212
+ clicked = true;
213
+ console.log(chalk.green('✅ 点击了连接按钮'));
214
+ break;
215
+ }
154
216
  }
155
217
  }
156
218
  catch (e) {
157
- // 继续尝试下一个选择器
219
+ // 继续
158
220
  }
159
221
  }
160
222
  if (!clicked) {
161
- // 打印页面上所有按钮,帮助调试
162
- const buttons = await this.page.$$eval('button', (btns) => btns.map(b => ({ text: b.textContent?.trim(), class: b.className, title: b.title })));
163
- console.log(chalk.gray('页面上的按钮:'), JSON.stringify(buttons, null, 2));
164
223
  console.log(chalk.yellow('⚠️ 未找到连接按钮,请手动点击连接'));
165
224
  }
166
225
  // 等待连接建立
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemini-proxy-client",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Gemini Proxy Build App 客户端 - 使用 Camoufox 自动保持连接",
5
5
  "main": "dist/index.js",
6
6
  "bin": {