gemini-proxy-client 1.0.7 → 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.
- package/dist/browser/manager.js +90 -97
- package/dist/cli.js +1 -1
- package/package.json +1 -1
package/dist/browser/manager.js
CHANGED
|
@@ -143,124 +143,117 @@ 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
|
-
//
|
|
147
|
+
// 第二步:关闭可能存在的模态框
|
|
149
148
|
try {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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);
|
|
164
163
|
}
|
|
165
164
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
console.log(chalk.green('✅ 点击了连接按钮 (主页面)'));
|
|
165
|
+
catch (e) {
|
|
166
|
+
// 忽略
|
|
167
|
+
}
|
|
170
168
|
}
|
|
171
169
|
}
|
|
172
170
|
catch (e) {
|
|
173
|
-
|
|
171
|
+
// 忽略
|
|
174
172
|
}
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
173
|
+
// 第三步:使用 frames() API 访问 Build App iframe
|
|
174
|
+
// Connect WS 按钮在 scf.usercontent.goog iframe 中
|
|
175
|
+
try {
|
|
176
|
+
console.log(chalk.gray('查找 Build App 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 内容加载
|
|
185
187
|
try {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
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) {
|
|
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;
|
|
202
207
|
}
|
|
203
|
-
|
|
204
|
-
|
|
208
|
+
}
|
|
209
|
+
catch (btnErr) {
|
|
210
|
+
console.log(chalk.gray(` 点击失败: ${btnErr}`));
|
|
211
|
+
}
|
|
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('✅ 点击了连接按钮 (选择器)'));
|
|
205
221
|
}
|
|
206
222
|
}
|
|
223
|
+
catch (e) {
|
|
224
|
+
console.log(chalk.gray(`选择器点击失败: ${e}`));
|
|
225
|
+
}
|
|
207
226
|
}
|
|
208
|
-
|
|
209
|
-
|
|
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;
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
});
|
|
238
|
+
if (clicked) {
|
|
239
|
+
console.log(chalk.green('✅ 点击了连接按钮 (evaluate)'));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
catch (e) {
|
|
243
|
+
console.log(chalk.gray(`evaluate 点击失败: ${e}`));
|
|
244
|
+
}
|
|
210
245
|
}
|
|
211
246
|
}
|
|
212
247
|
}
|
|
213
|
-
catch (e) {
|
|
214
|
-
console.log(chalk.gray(`Frame 遍历失败: ${e}`));
|
|
215
|
-
}
|
|
216
248
|
}
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
}
|
|
249
|
+
catch (e) {
|
|
250
|
+
console.log(chalk.gray(`iframe 访问失败: ${e}`));
|
|
240
251
|
}
|
|
241
|
-
//
|
|
252
|
+
// 第四步:设置服务器地址(如果有输入框)
|
|
242
253
|
await this.setServerAddress();
|
|
243
254
|
if (!clicked) {
|
|
244
255
|
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
|
-
}
|
|
256
|
+
console.log(chalk.gray('提示: Connect WS 按钮在 Build App 预览 iframe 中'));
|
|
264
257
|
}
|
|
265
258
|
// 等待连接建立
|
|
266
259
|
await sleep(3000);
|
package/dist/cli.js
CHANGED