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.
- package/dist/browser/manager.js +69 -46
- package/dist/cli.js +1 -1
- package/package.json +1 -1
package/dist/browser/manager.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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