gemini-proxy-client 1.0.9 → 1.0.10
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 +29 -23
- package/dist/cli.js +1 -1
- package/package.json +1 -1
package/dist/browser/manager.js
CHANGED
|
@@ -144,9 +144,9 @@ export class BrowserManager {
|
|
|
144
144
|
console.log(chalk.gray('未找到 "Continue to the app" 按钮,继续...'));
|
|
145
145
|
}
|
|
146
146
|
let clicked = false;
|
|
147
|
+
let buildAppFrame = null;
|
|
147
148
|
// 第二步:关闭可能存在的模态框
|
|
148
149
|
try {
|
|
149
|
-
// 尝试点击模态框外部或关闭按钮
|
|
150
150
|
const modalSelectors = [
|
|
151
151
|
'.interaction-modal',
|
|
152
152
|
'[class*="modal"]',
|
|
@@ -157,7 +157,6 @@ export class BrowserManager {
|
|
|
157
157
|
const modal = await this.page.$(selector);
|
|
158
158
|
if (modal) {
|
|
159
159
|
console.log(chalk.gray(`发现模态框: ${selector},尝试关闭...`));
|
|
160
|
-
// 尝试按 Escape 键关闭
|
|
161
160
|
await this.page.keyboard.press('Escape');
|
|
162
161
|
await sleep(500);
|
|
163
162
|
}
|
|
@@ -171,7 +170,6 @@ export class BrowserManager {
|
|
|
171
170
|
// 忽略
|
|
172
171
|
}
|
|
173
172
|
// 第三步:使用 frames() API 访问 Build App iframe
|
|
174
|
-
// Connect WS 按钮在 scf.usercontent.goog iframe 中
|
|
175
173
|
try {
|
|
176
174
|
console.log(chalk.gray('查找 Build App iframe...'));
|
|
177
175
|
const frames = this.page.frames();
|
|
@@ -183,6 +181,7 @@ export class BrowserManager {
|
|
|
183
181
|
// 查找 Build App iframe (可能是 blob: URL 或 scf.usercontent.goog)
|
|
184
182
|
if (frameUrl.includes('scf.usercontent.goog') || frameUrl.startsWith('blob:')) {
|
|
185
183
|
console.log(chalk.gray(`找到 Build App iframe: ${frameUrl.substring(0, 60)}...`));
|
|
184
|
+
buildAppFrame = frame;
|
|
186
185
|
// 等待 iframe 内容加载
|
|
187
186
|
try {
|
|
188
187
|
await frame.waitForLoadState('domcontentloaded');
|
|
@@ -210,21 +209,7 @@ export class BrowserManager {
|
|
|
210
209
|
console.log(chalk.gray(` 点击失败: ${btnErr}`));
|
|
211
210
|
}
|
|
212
211
|
}
|
|
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('✅ 点击了连接按钮 (选择器)'));
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
catch (e) {
|
|
224
|
-
console.log(chalk.gray(`选择器点击失败: ${e}`));
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
// 如果还是没成功,尝试 evaluate 直接执行点击
|
|
212
|
+
// 如果遍历没找到,尝试 evaluate 直接执行点击
|
|
228
213
|
if (!clicked) {
|
|
229
214
|
try {
|
|
230
215
|
clicked = await frame.evaluate(() => {
|
|
@@ -249,14 +234,35 @@ export class BrowserManager {
|
|
|
249
234
|
catch (e) {
|
|
250
235
|
console.log(chalk.gray(`iframe 访问失败: ${e}`));
|
|
251
236
|
}
|
|
252
|
-
// 第四步:设置服务器地址(如果有输入框)
|
|
253
|
-
await this.setServerAddress();
|
|
254
237
|
if (!clicked) {
|
|
255
238
|
console.log(chalk.yellow('⚠️ 未找到连接按钮,请手动点击连接'));
|
|
256
|
-
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
// 第四步:等待并验证连接成功(按钮文字变成 "Disconnect WS")
|
|
242
|
+
console.log(chalk.gray('等待 WebSocket 连接...'));
|
|
243
|
+
let connected = false;
|
|
244
|
+
for (let i = 0; i < 10; i++) { // 最多等待 10 秒
|
|
245
|
+
await sleep(1000);
|
|
246
|
+
if (buildAppFrame) {
|
|
247
|
+
try {
|
|
248
|
+
const buttonText = await buildAppFrame.evaluate(() => {
|
|
249
|
+
const btn = document.querySelector('button[title="Connect WebSocket Proxy"], button[title="Disconnect WebSocket Proxy"]');
|
|
250
|
+
return btn?.textContent?.trim() || '';
|
|
251
|
+
});
|
|
252
|
+
if (buttonText.includes('Disconnect')) {
|
|
253
|
+
connected = true;
|
|
254
|
+
console.log(chalk.green('✅ WebSocket 连接成功!'));
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
catch (e) {
|
|
259
|
+
// 忽略
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (!connected) {
|
|
264
|
+
console.log(chalk.yellow('⚠️ WebSocket 连接可能未成功,请检查'));
|
|
257
265
|
}
|
|
258
|
-
// 等待连接建立
|
|
259
|
-
await sleep(3000);
|
|
260
266
|
}
|
|
261
267
|
/**
|
|
262
268
|
* 设置服务器地址
|
package/dist/cli.js
CHANGED