chrome-ai-bridge 1.0.10 → 1.0.11

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.
@@ -282,6 +282,9 @@ export const askGeminiImage = defineTool({
282
282
  downloadManager.on('started', (filename) => {
283
283
  response.appendResponseLine(`📥 ダウンロード開始: ${filename}`);
284
284
  });
285
+ // Get existing Gemini images BEFORE clicking download button
286
+ const existingFiles = await fs.promises.readdir(userDownloadsDir);
287
+ const existingGeminiImages = new Set(existingFiles.filter(f => f.startsWith('Gemini_Generated_Image_') && f.endsWith('.png')));
285
288
  // Click download button - Gemini uses "フルサイズの画像をダウンロード" button
286
289
  // Improved selector: prioritize aria-describedby for more reliable detection
287
290
  const downloadClicked = await page.evaluate(() => {
@@ -325,25 +328,41 @@ export const askGeminiImage = defineTool({
325
328
  response.appendResponseLine('ヒント: ブラウザで画像を右クリックして保存してください');
326
329
  return;
327
330
  }
328
- // Wait for download to complete using CDP events (more reliable than file polling)
329
- response.appendResponseLine('⏳ CDP経由でダウンロード完了を待機中...');
330
- let downloadedPath;
331
- try {
332
- downloadedPath = await downloadManager.waitForDownload(60000); // 60 seconds
333
- response.appendResponseLine(`✅ ダウンロード完了: ${path.basename(downloadedPath)}`);
334
- }
335
- catch (downloadError) {
336
- const errMsg = downloadError instanceof Error ? downloadError.message : String(downloadError);
337
- if (errMsg.includes('timeout')) {
338
- response.appendResponseLine('❌ ダウンロードタイムアウト (60秒)');
339
- response.appendResponseLine('💡 ヒント: ブラウザで画像を右クリックして「画像を保存」してください');
331
+ // Wait for download to complete using hybrid approach:
332
+ // 1. Try CDP events first (reliable for standard downloads)
333
+ // 2. Fall back to filesystem monitoring (for blob/JS downloads like Gemini)
334
+ response.appendResponseLine('⏳ ダウンロード完了を待機中...');
335
+ let downloadedPath = null;
336
+ const downloadStartTime = Date.now();
337
+ const downloadTimeout = 60000; // 60 seconds
338
+ // Try CDP-based detection with filesystem fallback
339
+ while (Date.now() - downloadStartTime < downloadTimeout) {
340
+ // Check for new Gemini image files (filesystem fallback)
341
+ const currentFiles = await fs.promises.readdir(userDownloadsDir);
342
+ const newGeminiImages = currentFiles.filter(f => f.startsWith('Gemini_Generated_Image_') &&
343
+ f.endsWith('.png') &&
344
+ !existingGeminiImages.has(f));
345
+ if (newGeminiImages.length > 0) {
346
+ // Found new image file
347
+ const newestImage = newGeminiImages.sort().pop();
348
+ downloadedPath = path.join(userDownloadsDir, newestImage);
349
+ // Wait a bit for file to be fully written
350
+ await new Promise(resolve => setTimeout(resolve, 500));
351
+ response.appendResponseLine(`✅ ダウンロード完了: ${newestImage}`);
352
+ break;
340
353
  }
341
- else if (errMsg.includes('canceled')) {
342
- response.appendResponseLine('❌ ダウンロードがキャンセルされました');
343
- }
344
- else {
345
- response.appendResponseLine(`❌ ダウンロードエラー: ${errMsg}`);
354
+ // Also check CDP events (for standard downloads)
355
+ const completedDownloads = Array.from(downloadManager.getPendingDownloads()).filter((d) => d.state === 'completed');
356
+ if (completedDownloads.length > 0) {
357
+ // CDP detected completion - but Gemini uses blob downloads so this rarely fires
358
+ break;
346
359
  }
360
+ // Short wait before next check
361
+ await new Promise(resolve => setTimeout(resolve, 500));
362
+ }
363
+ if (!downloadedPath) {
364
+ response.appendResponseLine('❌ ダウンロードタイムアウト (60秒)');
365
+ response.appendResponseLine('💡 ヒント: ブラウザで画像を右クリックして「画像を保存」してください');
347
366
  return;
348
367
  }
349
368
  // Ensure output directory exists
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-ai-bridge",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "MCP server bridging Chrome browser and AI assistants (ChatGPT, Gemini). Browser automation + AI consultation.",
5
5
  "type": "module",
6
6
  "bin": "./scripts/cli.mjs",