gemini-proxy-client 1.0.9 → 1.0.11

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.
@@ -144,9 +144,9 @@ export class BrowserManager {
144
144
  console.log(chalk.gray('未找到 "Continue to the app" 按钮,继续...'));
145
145
  }
146
146
  let clicked = false;
147
+ let buildAppFrame = null;
147
148
  // 第二步:关闭可能存在的模态框
148
149
  try {
149
- // 尝试点击模态框外部或关闭按钮
150
150
  const modalSelectors = [
151
151
  '.interaction-modal',
152
152
  '[class*="modal"]',
@@ -157,7 +157,6 @@ export class BrowserManager {
157
157
  const modal = await this.page.$(selector);
158
158
  if (modal) {
159
159
  console.log(chalk.gray(`发现模态框: ${selector},尝试关闭...`));
160
- // 尝试按 Escape 键关闭
161
160
  await this.page.keyboard.press('Escape');
162
161
  await sleep(500);
163
162
  }
@@ -171,7 +170,6 @@ export class BrowserManager {
171
170
  // 忽略
172
171
  }
173
172
  // 第三步:使用 frames() API 访问 Build App iframe
174
- // Connect WS 按钮在 scf.usercontent.goog iframe 中
175
173
  try {
176
174
  console.log(chalk.gray('查找 Build App iframe...'));
177
175
  const frames = this.page.frames();
@@ -183,6 +181,7 @@ export class BrowserManager {
183
181
  // 查找 Build App iframe (可能是 blob: URL 或 scf.usercontent.goog)
184
182
  if (frameUrl.includes('scf.usercontent.goog') || frameUrl.startsWith('blob:')) {
185
183
  console.log(chalk.gray(`找到 Build App iframe: ${frameUrl.substring(0, 60)}...`));
184
+ buildAppFrame = frame;
186
185
  // 等待 iframe 内容加载
187
186
  try {
188
187
  await frame.waitForLoadState('domcontentloaded');
@@ -190,41 +189,31 @@ export class BrowserManager {
190
189
  catch (e) {
191
190
  // 忽略
192
191
  }
193
- // 查找按钮
194
- const buttons = await frame.$$('button');
195
- console.log(chalk.gray(` iframe 中找到 ${buttons.length} 个按钮`));
196
- for (const button of buttons) {
197
- try {
198
- const title = await button.getAttribute('title');
199
- const text = await button.textContent();
200
- console.log(chalk.gray(` 按钮: "${text?.trim()}" title="${title}"`));
201
- if (title === 'Connect WebSocket Proxy' || (text && text.includes('Connect WS'))) {
202
- // 使用 force: true 强制点击,忽略遮挡
203
- await button.click({ force: true });
204
- clicked = true;
205
- console.log(chalk.green('✅ 点击了连接按钮'));
206
- break;
192
+ // 直接使用 evaluate 在 iframe 中执行点击
193
+ // 这样可以绑过任何遮挡问题
194
+ try {
195
+ clicked = await frame.evaluate(() => {
196
+ const btn = document.querySelector('button[title="Connect WebSocket Proxy"]');
197
+ if (btn) {
198
+ // 使用 dispatchEvent 触发真实的点击事件
199
+ const clickEvent = new MouseEvent('click', {
200
+ bubbles: true,
201
+ cancelable: true,
202
+ view: window
203
+ });
204
+ btn.dispatchEvent(clickEvent);
205
+ return true;
207
206
  }
208
- }
209
- catch (btnErr) {
210
- console.log(chalk.gray(` 点击失败: ${btnErr}`));
207
+ return false;
208
+ });
209
+ if (clicked) {
210
+ console.log(chalk.green('✅ 点击了连接按钮'));
211
211
  }
212
212
  }
213
- // 如果遍历没找到,尝试选择器
214
- if (!clicked) {
215
- try {
216
- const button = await frame.$('button[title="Connect WebSocket Proxy"]');
217
- if (button) {
218
- await button.click({ force: true });
219
- clicked = true;
220
- console.log(chalk.green('✅ 点击了连接按钮 (选择器)'));
221
- }
222
- }
223
- catch (e) {
224
- console.log(chalk.gray(`选择器点击失败: ${e}`));
225
- }
213
+ catch (e) {
214
+ console.log(chalk.gray(`evaluate 点击失败: ${e}`));
226
215
  }
227
- // 如果还是没成功,尝试 evaluate 直接执行点击
216
+ // 如果 dispatchEvent 失败,尝试直接调用 onclick
228
217
  if (!clicked) {
229
218
  try {
230
219
  clicked = await frame.evaluate(() => {
@@ -236,11 +225,11 @@ export class BrowserManager {
236
225
  return false;
237
226
  });
238
227
  if (clicked) {
239
- console.log(chalk.green('✅ 点击了连接按钮 (evaluate)'));
228
+ console.log(chalk.green('✅ 点击了连接按钮 (click())'));
240
229
  }
241
230
  }
242
231
  catch (e) {
243
- console.log(chalk.gray(`evaluate 点击失败: ${e}`));
232
+ console.log(chalk.gray(`click() 失败: ${e}`));
244
233
  }
245
234
  }
246
235
  }
@@ -249,14 +238,36 @@ export class BrowserManager {
249
238
  catch (e) {
250
239
  console.log(chalk.gray(`iframe 访问失败: ${e}`));
251
240
  }
252
- // 第四步:设置服务器地址(如果有输入框)
253
- await this.setServerAddress();
254
241
  if (!clicked) {
255
242
  console.log(chalk.yellow('⚠️ 未找到连接按钮,请手动点击连接'));
256
- console.log(chalk.gray('提示: Connect WS 按钮在 Build App 预览 iframe 中'));
243
+ return;
244
+ }
245
+ // 第四步:等待并验证连接成功(按钮文字变成 "Disconnect WS")
246
+ console.log(chalk.gray('等待 WebSocket 连接...'));
247
+ let connected = false;
248
+ for (let i = 0; i < 15; i++) { // 最多等待 15 秒
249
+ await sleep(1000);
250
+ if (buildAppFrame) {
251
+ try {
252
+ const buttonText = await buildAppFrame.evaluate(() => {
253
+ const btn = document.querySelector('button[title="Connect WebSocket Proxy"], button[title="Disconnect WebSocket Proxy"]');
254
+ return btn?.textContent?.trim() || '';
255
+ });
256
+ console.log(chalk.gray(` 检测按钮文字: "${buttonText}"`));
257
+ if (buttonText.includes('Disconnect')) {
258
+ connected = true;
259
+ console.log(chalk.green('✅ WebSocket 连接成功!'));
260
+ break;
261
+ }
262
+ }
263
+ catch (e) {
264
+ // 忽略
265
+ }
266
+ }
267
+ }
268
+ if (!connected) {
269
+ console.log(chalk.yellow('⚠️ WebSocket 连接可能未成功,请检查'));
257
270
  }
258
- // 等待连接建立
259
- await sleep(3000);
260
271
  }
261
272
  /**
262
273
  * 设置服务器地址
package/dist/cli.js CHANGED
@@ -12,7 +12,7 @@ const program = new Command();
12
12
  program
13
13
  .name('gemini-client')
14
14
  .description('Gemini Proxy Build App 客户端 - 使用 Camoufox 自动保持连接')
15
- .version('1.0.9');
15
+ .version('1.0.11');
16
16
  program
17
17
  .command('start')
18
18
  .description('启动客户端,连接到代理服务器')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemini-proxy-client",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Gemini Proxy Build App 客户端 - 使用 Camoufox 自动保持连接",
5
5
  "main": "dist/index.js",
6
6
  "bin": {