gemini-proxy-client 1.0.7 → 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.
@@ -143,124 +143,87 @@ export class BrowserManager {
143
143
  catch (e) {
144
144
  console.log(chalk.gray('未找到 "Continue to the app" 按钮,继续...'));
145
145
  }
146
- // 第二步:直接在主页面查找按钮(不通过 frames)
147
146
  let clicked = false;
148
- // 方法1: 使用 page.evaluate 直接在页面中查找并点击
147
+ // 第二步:使用 frameLocator 访问 Build App iframe
148
+ // Connect WS 按钮在 scf.usercontent.goog iframe 中
149
149
  try {
150
- console.log(chalk.gray('尝试在主页面查找按钮...'));
151
- clicked = await this.page.evaluate(() => {
152
- // 查找所有按钮
153
- const buttons = document.querySelectorAll('button');
154
- console.log('Found buttons:', buttons.length);
155
- for (const button of buttons) {
156
- const title = button.getAttribute('title');
157
- const ariaLabel = button.getAttribute('aria-label');
158
- const text = button.textContent || '';
159
- if (title === 'Connect WebSocket Proxy' ||
160
- ariaLabel === 'Connect WebSocket Proxy' ||
161
- text.includes('Connect WS')) {
162
- button.click();
163
- return true;
164
- }
165
- }
166
- return false;
167
- });
168
- if (clicked) {
169
- console.log(chalk.green('✅ 点击了连接按钮 (主页面)'));
170
- }
171
- }
172
- catch (e) {
173
- console.log(chalk.gray(`主页面查找失败: ${e}`));
174
- }
175
- // 方法2: 如果主页面没找到,检查 iframe
176
- if (!clicked) {
150
+ console.log(chalk.gray('查找 Build App iframe...'));
151
+ // 方法1: 使用 frameLocator (推荐方式)
152
+ const iframeLocator = this.page.frameLocator('iframe[src*="scf.usercontent.goog"]');
153
+ // 等待 iframe 中的按钮出现
177
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) {
178
166
  const frames = this.page.frames();
179
167
  console.log(chalk.gray(`检查 ${frames.length} 个 frame...`));
180
168
  for (const frame of frames) {
181
169
  if (clicked)
182
170
  break;
183
171
  const frameUrl = frame.url();
184
- console.log(chalk.gray(` Frame: ${frameUrl.substring(0, 80)}`));
185
- try {
186
- // 在每个 frame 中查找按钮
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
+ // 查找按钮
187
183
  const buttons = await frame.$$('button');
188
- console.log(chalk.gray(` 找到 ${buttons.length} 个按钮`));
184
+ console.log(chalk.gray(` iframe 中找到 ${buttons.length} 个按钮`));
189
185
  for (const button of buttons) {
190
186
  try {
191
187
  const title = await button.getAttribute('title');
192
- const ariaLabel = await button.getAttribute('aria-label');
193
188
  const text = await button.textContent();
194
- if (title === 'Connect WebSocket Proxy' ||
195
- ariaLabel === 'Connect WebSocket Proxy' ||
196
- (text && text.includes('Connect WS'))) {
189
+ console.log(chalk.gray(` 按钮: "${text?.trim()}" title="${title}"`));
190
+ if (title === 'Connect WebSocket Proxy' || (text && text.includes('Connect WS'))) {
197
191
  await button.click();
198
192
  clicked = true;
199
- console.log(chalk.green('✅ 点击了连接按钮 (iframe)'));
193
+ console.log(chalk.green('✅ 点击了连接按钮 (frame API)'));
200
194
  break;
201
195
  }
202
196
  }
203
197
  catch (btnErr) {
204
- // 单个按钮处理失败,继续下一个
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
+ // 继续
205
213
  }
206
214
  }
207
- }
208
- catch (frameErr) {
209
- console.log(chalk.gray(` Frame 处理失败: ${frameErr}`));
210
215
  }
211
216
  }
212
217
  }
213
- catch (e) {
214
- console.log(chalk.gray(`Frame 遍历失败: ${e}`));
215
- }
216
218
  }
217
- // 方法3: 使用 CSS 选择器直接查找
218
- if (!clicked) {
219
- const selectors = [
220
- 'button[title="Connect WebSocket Proxy"]',
221
- 'button[aria-label="Connect WebSocket Proxy"]',
222
- 'button:has-text("Connect WS")',
223
- 'button.bg-green-500:has(span:text("Connect"))',
224
- ];
225
- for (const selector of selectors) {
226
- try {
227
- console.log(chalk.gray(`尝试选择器: ${selector}`));
228
- const button = await this.page.$(selector);
229
- if (button) {
230
- await button.click();
231
- clicked = true;
232
- console.log(chalk.green(`✅ 点击了连接按钮 (选择器: ${selector})`));
233
- break;
234
- }
235
- }
236
- catch (e) {
237
- // 继续尝试下一个选择器
238
- }
239
- }
219
+ catch (e) {
220
+ console.log(chalk.gray(`iframe 访问失败: ${e}`));
240
221
  }
241
222
  // 第三步:设置服务器地址(如果有输入框)
242
223
  await this.setServerAddress();
243
224
  if (!clicked) {
244
225
  console.log(chalk.yellow('⚠️ 未找到连接按钮,请手动点击连接'));
245
- // 打印页面上所有按钮的信息以便调试
246
- try {
247
- const buttonInfo = await this.page.evaluate(() => {
248
- const buttons = document.querySelectorAll('button');
249
- return Array.from(buttons).map(b => ({
250
- text: b.textContent?.trim().substring(0, 50),
251
- title: b.getAttribute('title'),
252
- ariaLabel: b.getAttribute('aria-label'),
253
- className: b.className.substring(0, 50),
254
- }));
255
- });
256
- console.log(chalk.gray('页面按钮信息:'));
257
- buttonInfo.forEach((info, i) => {
258
- console.log(chalk.gray(` ${i + 1}. text="${info.text}" title="${info.title}" aria="${info.ariaLabel}"`));
259
- });
260
- }
261
- catch (e) {
262
- // 忽略调试信息获取失败
263
- }
226
+ console.log(chalk.gray('提示: Connect WS 按钮在 Build App 预览 iframe 中'));
264
227
  }
265
228
  // 等待连接建立
266
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.7');
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.7",
3
+ "version": "1.0.8",
4
4
  "description": "Gemini Proxy Build App 客户端 - 使用 Camoufox 自动保持连接",
5
5
  "main": "dist/index.js",
6
6
  "bin": {