gemini-proxy-client 1.0.8 → 1.0.9

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,73 +144,103 @@ export class BrowserManager {
144
144
  console.log(chalk.gray('未找到 "Continue to the app" 按钮,继续...'));
145
145
  }
146
146
  let clicked = false;
147
- // 第二步:使用 frameLocator 访问 Build App iframe
147
+ // 第二步:关闭可能存在的模态框
148
+ try {
149
+ // 尝试点击模态框外部或关闭按钮
150
+ const modalSelectors = [
151
+ '.interaction-modal',
152
+ '[class*="modal"]',
153
+ '.overlay',
154
+ ];
155
+ for (const selector of modalSelectors) {
156
+ try {
157
+ const modal = await this.page.$(selector);
158
+ if (modal) {
159
+ console.log(chalk.gray(`发现模态框: ${selector},尝试关闭...`));
160
+ // 尝试按 Escape 键关闭
161
+ await this.page.keyboard.press('Escape');
162
+ await sleep(500);
163
+ }
164
+ }
165
+ catch (e) {
166
+ // 忽略
167
+ }
168
+ }
169
+ }
170
+ catch (e) {
171
+ // 忽略
172
+ }
173
+ // 第三步:使用 frames() API 访问 Build App iframe
148
174
  // Connect WS 按钮在 scf.usercontent.goog iframe 中
149
175
  try {
150
176
  console.log(chalk.gray('查找 Build App iframe...'));
151
- // 方法1: 使用 frameLocator (推荐方式)
152
- const iframeLocator = this.page.frameLocator('iframe[src*="scf.usercontent.goog"]');
153
- // 等待 iframe 中的按钮出现
154
- try {
155
- const connectButton = iframeLocator.locator('button[title="Connect WebSocket Proxy"]');
156
- await connectButton.waitFor({ timeout: 10000 });
157
- await connectButton.click();
158
- clicked = true;
159
- console.log(chalk.green('✅ 点击了连接按钮 (frameLocator)'));
160
- }
161
- catch (e) {
162
- console.log(chalk.gray(`frameLocator 方法失败: ${e}`));
163
- }
164
- // 方法2: 如果 frameLocator 失败,尝试通过 frames() API
165
- if (!clicked) {
166
- const frames = this.page.frames();
167
- console.log(chalk.gray(`检查 ${frames.length} 个 frame...`));
168
- for (const frame of frames) {
169
- if (clicked)
170
- break;
171
- const frameUrl = frame.url();
172
- // 查找 Build App iframe
173
- if (frameUrl.includes('scf.usercontent.goog')) {
174
- console.log(chalk.gray(`找到 Build App iframe: ${frameUrl.substring(0, 60)}...`));
175
- // 等待 iframe 内容加载
177
+ const frames = this.page.frames();
178
+ console.log(chalk.gray(`检查 ${frames.length} 个 frame...`));
179
+ for (const frame of frames) {
180
+ if (clicked)
181
+ break;
182
+ const frameUrl = frame.url();
183
+ // 查找 Build App iframe (可能是 blob: URL 或 scf.usercontent.goog)
184
+ if (frameUrl.includes('scf.usercontent.goog') || frameUrl.startsWith('blob:')) {
185
+ console.log(chalk.gray(`找到 Build App iframe: ${frameUrl.substring(0, 60)}...`));
186
+ // 等待 iframe 内容加载
187
+ try {
188
+ await frame.waitForLoadState('domcontentloaded');
189
+ }
190
+ catch (e) {
191
+ // 忽略
192
+ }
193
+ // 查找按钮
194
+ const buttons = await frame.$$('button');
195
+ console.log(chalk.gray(` iframe 中找到 ${buttons.length} 个按钮`));
196
+ for (const button of buttons) {
176
197
  try {
177
- await frame.waitForLoadState('domcontentloaded');
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;
207
+ }
178
208
  }
179
- catch (e) {
180
- // 忽略
209
+ catch (btnErr) {
210
+ console.log(chalk.gray(` 点击失败: ${btnErr}`));
181
211
  }
182
- // 查找按钮
183
- const buttons = await frame.$$('button');
184
- console.log(chalk.gray(` iframe 中找到 ${buttons.length} 个按钮`));
185
- for (const button of buttons) {
186
- try {
187
- const title = await button.getAttribute('title');
188
- const text = await button.textContent();
189
- console.log(chalk.gray(` 按钮: "${text?.trim()}" title="${title}"`));
190
- if (title === 'Connect WebSocket Proxy' || (text && text.includes('Connect WS'))) {
191
- await button.click();
192
- clicked = true;
193
- console.log(chalk.green('✅ 点击了连接按钮 (frame API)'));
194
- break;
195
- }
196
- }
197
- catch (btnErr) {
198
- // 继续
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(' 点击了连接按钮 (选择器)'));
199
221
  }
200
222
  }
201
- // 如果遍历没找到,尝试选择器
202
- if (!clicked) {
203
- try {
204
- const button = await frame.$('button[title="Connect WebSocket Proxy"]');
205
- if (button) {
206
- await button.click();
207
- clicked = true;
208
- console.log(chalk.green('✅ 点击了连接按钮 (选择器)'));
223
+ catch (e) {
224
+ console.log(chalk.gray(`选择器点击失败: ${e}`));
225
+ }
226
+ }
227
+ // 如果还是没成功,尝试 evaluate 直接执行点击
228
+ if (!clicked) {
229
+ try {
230
+ clicked = await frame.evaluate(() => {
231
+ const btn = document.querySelector('button[title="Connect WebSocket Proxy"]');
232
+ if (btn) {
233
+ btn.click();
234
+ return true;
209
235
  }
236
+ return false;
237
+ });
238
+ if (clicked) {
239
+ console.log(chalk.green('✅ 点击了连接按钮 (evaluate)'));
210
240
  }
211
- catch (e) {
212
- // 继续
213
- }
241
+ }
242
+ catch (e) {
243
+ console.log(chalk.gray(`evaluate 点击失败: ${e}`));
214
244
  }
215
245
  }
216
246
  }
@@ -219,7 +249,7 @@ export class BrowserManager {
219
249
  catch (e) {
220
250
  console.log(chalk.gray(`iframe 访问失败: ${e}`));
221
251
  }
222
- // 第三步:设置服务器地址(如果有输入框)
252
+ // 第四步:设置服务器地址(如果有输入框)
223
253
  await this.setServerAddress();
224
254
  if (!clicked) {
225
255
  console.log(chalk.yellow('⚠️ 未找到连接按钮,请手动点击连接'));
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.8');
15
+ .version('1.0.9');
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.8",
3
+ "version": "1.0.9",
4
4
  "description": "Gemini Proxy Build App 客户端 - 使用 Camoufox 自动保持连接",
5
5
  "main": "dist/index.js",
6
6
  "bin": {