gemini-proxy-client 1.0.6 → 1.0.8

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.
@@ -128,6 +128,7 @@ export class BrowserManager {
128
128
  async clickConnectButton() {
129
129
  if (!this.page)
130
130
  throw new Error('Browser not launched');
131
+ console.log(chalk.gray('开始查找连接按钮...'));
131
132
  // 等待页面完全加载
132
133
  await sleep(3000);
133
134
  // 第一步:点击 "Continue to the app" 按钮(如果存在)
@@ -140,67 +141,89 @@ export class BrowserManager {
140
141
  }
141
142
  }
142
143
  catch (e) {
143
- // 按钮不存在,可能已经在 app 页面了
144
+ console.log(chalk.gray('未找到 "Continue to the app" 按钮,继续...'));
144
145
  }
145
- // 检查是否有 iframe
146
- const frames = this.page.frames();
147
- console.log(chalk.gray(`页面有 ${frames.length} 个 frame`));
148
- // 在所有 frame 中查找按钮
149
146
  let clicked = false;
150
- for (const frame of frames) {
151
- if (clicked)
152
- break;
153
- // 打印当前 frame 的 URL
154
- const frameUrl = frame.url();
155
- if (frameUrl && frameUrl !== 'about:blank') {
156
- console.log(chalk.gray(`检查 frame: ${frameUrl.substring(0, 50)}...`));
157
- }
158
- // 方法1: 遍历所有按钮找文字
147
+ // 第二步:使用 frameLocator 访问 Build App iframe
148
+ // Connect WS 按钮在 scf.usercontent.goog iframe 中
149
+ try {
150
+ console.log(chalk.gray('查找 Build App iframe...'));
151
+ // 方法1: 使用 frameLocator (推荐方式)
152
+ const iframeLocator = this.page.frameLocator('iframe[src*="scf.usercontent.goog"]');
153
+ // 等待 iframe 中的按钮出现
159
154
  try {
160
- const buttons = await frame.$$('button');
161
- console.log(chalk.gray(` 找到 ${buttons.length} 个按钮`));
162
- for (const button of buttons) {
163
- const text = await button.textContent();
164
- const title = await button.getAttribute('title');
165
- if ((text && text.includes('Connect WS')) ||
166
- (title && title.includes('Connect WebSocket'))) {
167
- await button.click();
168
- clicked = true;
169
- console.log(chalk.green('✅ 点击了连接按钮'));
170
- break;
171
- }
172
- }
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)'));
173
160
  }
174
161
  catch (e) {
175
- // 继续
162
+ console.log(chalk.gray(`frameLocator 方法失败: ${e}`));
176
163
  }
177
- // 方法2: 通过选择器
164
+ // 方法2: 如果 frameLocator 失败,尝试通过 frames() API
178
165
  if (!clicked) {
179
- const selectors = [
180
- 'button[aria-label="Connect WebSocket Proxy"]',
181
- 'button[title="Connect WebSocket Proxy"]',
182
- 'button.bg-green-500',
183
- ];
184
- for (const selector of selectors) {
185
- try {
186
- const button = await frame.$(selector);
187
- if (button) {
188
- await button.click();
189
- clicked = true;
190
- console.log(chalk.green('✅ 点击了连接按钮'));
191
- break;
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 内容加载
176
+ try {
177
+ await frame.waitForLoadState('domcontentloaded');
178
+ }
179
+ catch (e) {
180
+ // 忽略
181
+ }
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
+ // 继续
199
+ }
200
+ }
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('✅ 点击了连接按钮 (选择器)'));
209
+ }
210
+ }
211
+ catch (e) {
212
+ // 继续
213
+ }
192
214
  }
193
- }
194
- catch (e) {
195
- // 继续
196
215
  }
197
216
  }
198
217
  }
199
218
  }
200
- // 第二步:设置服务器地址(如果有输入框)
219
+ catch (e) {
220
+ console.log(chalk.gray(`iframe 访问失败: ${e}`));
221
+ }
222
+ // 第三步:设置服务器地址(如果有输入框)
201
223
  await this.setServerAddress();
202
224
  if (!clicked) {
203
225
  console.log(chalk.yellow('⚠️ 未找到连接按钮,请手动点击连接'));
226
+ console.log(chalk.gray('提示: Connect WS 按钮在 Build App 预览 iframe 中'));
204
227
  }
205
228
  // 等待连接建立
206
229
  await sleep(3000);
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.0');
15
+ .version('1.0.8');
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.6",
3
+ "version": "1.0.8",
4
4
  "description": "Gemini Proxy Build App 客户端 - 使用 Camoufox 自动保持连接",
5
5
  "main": "dist/index.js",
6
6
  "bin": {