holyterra commited on
Commit
8c92428
·
verified ·
1 Parent(s): d497f69

Upload unified-server.js

Browse files
Files changed (1) hide show
  1. unified-server.js +15 -7
unified-server.js CHANGED
@@ -271,15 +271,19 @@ class BrowserManager {
271
  });
272
  this.page = await this.context.newPage();
273
  this.logger.info(`[浏览器] 正在加载账号 ${authIndex} 并访问目标网页...`);
274
- const targetUrl = 'https://aistudio.google.com/u/0/apps/bundled/blank?showPreview=true&showCode=true&showAssistant=true';
275
  await this.page.goto(targetUrl, { timeout: 120000, waitUntil: 'networkidle' });
276
  this.logger.info('[浏览器] 网页加载完成,正在注入客户端脚本...');
277
 
 
 
 
 
278
  const editorContainerLocator = this.page.locator('div.monaco-editor').first();
279
 
280
- this.logger.info('[浏览器] 等待编辑器出现,最长120秒...');
281
- await editorContainerLocator.waitFor({ state: 'visible', timeout: 120000 });
282
- this.logger.info('[浏览器] 编辑器已出现,准备粘贴脚本。');
283
 
284
  this.logger.info('[浏览器] 等待5秒,之后将在页面下方执行一次模拟点击以确保页面激活...');
285
  await this.page.waitForTimeout(5000);
@@ -294,12 +298,16 @@ class BrowserManager {
294
  this.logger.warn('[浏览器] 无法获取视窗大小,跳过页面底部模拟点击。');
295
  }
296
 
297
- await editorContainerLocator.click({ timeout: 120000 });
298
  await this.page.evaluate(text => navigator.clipboard.writeText(text), buildScriptContent);
299
  const isMac = os.platform() === 'darwin';
300
  const pasteKey = isMac ? 'Meta+V' : 'Control+V';
301
  await this.page.keyboard.press(pasteKey);
302
- this.logger.info('[浏览器] 脚本已粘贴。浏览器端初始化完成。');
 
 
 
 
303
 
304
 
305
  this.currentAuthIndex = authIndex;
@@ -1835,4 +1843,4 @@ if (require.main === module) {
1835
  initializeServer();
1836
  }
1837
 
1838
- module.exports = { ProxyServerSystem, BrowserManager, initializeServer };
 
271
  });
272
  this.page = await this.context.newPage();
273
  this.logger.info(`[浏览器] 正在加载账号 ${authIndex} 并访问目标网页...`);
274
+ const targetUrl = 'https://aistudio.google.com/u/0/apps/bundled/blank?showAssistant=true&showCode=true';
275
  await this.page.goto(targetUrl, { timeout: 120000, waitUntil: 'networkidle' });
276
  this.logger.info('[浏览器] 网页加载完成,正在注入客户端脚本...');
277
 
278
+ this.logger.info('[浏览器] 正在点击 "Code" 按钮以切换到代码视图...');
279
+ await this.page.getByRole('button', { name: 'Code' }).click();
280
+ this.logger.info('[浏览器] 已切换到代码视图。');
281
+
282
  const editorContainerLocator = this.page.locator('div.monaco-editor').first();
283
 
284
+ this.logger.info('[浏览器] 等待编辑器附加到DOM,最长120秒...');
285
+ await editorContainerLocator.waitFor({ state: 'attached', timeout: 120000 });
286
+ this.logger.info('[浏览器] 编辑器已附加。');
287
 
288
  this.logger.info('[浏览器] 等待5秒,之后将在页面下方执行一次模拟点击以确保页面激活...');
289
  await this.page.waitForTimeout(5000);
 
298
  this.logger.warn('[浏览器] 无法获取视窗大小,跳过页面底部模拟点击。');
299
  }
300
 
301
+ await editorContainerLocator.click({ force: true, timeout: 120000 });
302
  await this.page.evaluate(text => navigator.clipboard.writeText(text), buildScriptContent);
303
  const isMac = os.platform() === 'darwin';
304
  const pasteKey = isMac ? 'Meta+V' : 'Control+V';
305
  await this.page.keyboard.press(pasteKey);
306
+ this.logger.info('[浏览器] 脚本已粘贴。');
307
+
308
+ this.logger.info('[浏览器] 正在点击 "Preview" 按钮以使代码生效...');
309
+ await this.page.getByRole('button', { name: 'Preview' }).click();
310
+ this.logger.info('[浏览器] 已切换到预览视图。浏览器端初始化完成。');
311
 
312
 
313
  this.currentAuthIndex = authIndex;
 
1843
  initializeServer();
1844
  }
1845
 
1846
+ module.exports = { ProxyServerSystem, BrowserManager, initializeServer };