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.
- package/build/src/tools/gemini-image.js +36 -17
- package/package.json +1 -1
|
@@ -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
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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