chrome-devtools-mcp-for-extension 0.22.2 → 0.22.4

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.
@@ -40,6 +40,7 @@ async function navigateWithRetry(page, url, options = { waitUntil: 'networkidle2
40
40
  /**
41
41
  * Find or create a dedicated ChatGPT tab
42
42
  * Returns existing ChatGPT tab if found, otherwise creates a new one
43
+ * Also returns whether navigation is needed
43
44
  */
44
45
  async function getOrCreateChatGPTPage(context) {
45
46
  // Refresh pages list
@@ -49,12 +50,13 @@ async function getOrCreateChatGPTPage(context) {
49
50
  for (const page of pages) {
50
51
  const url = page.url();
51
52
  if (url.includes('chatgpt.com') || url.includes('chat.openai.com')) {
52
- return page;
53
+ // Already on ChatGPT - no navigation needed
54
+ return { page, needsNavigation: false };
53
55
  }
54
56
  }
55
57
  // No ChatGPT tab found, create a new one
56
58
  const newPage = await context.newPage();
57
- return newPage;
59
+ return { page: newPage, needsNavigation: true };
58
60
  }
59
61
  /**
60
62
  * Path to store chat session data
@@ -228,13 +230,18 @@ export const askChatGPTWeb = defineTool({
228
230
  // Determine project name
229
231
  const project = projectName || path.basename(process.cwd()) || 'unknown-project';
230
232
  // Get or create a dedicated ChatGPT tab
231
- const page = await getOrCreateChatGPTPage(context);
233
+ const { page, needsNavigation } = await getOrCreateChatGPTPage(context);
232
234
  try {
233
- // Step 1: Navigate to ChatGPT
235
+ // Step 1: Navigate to ChatGPT (only if not already there)
234
236
  response.appendResponseLine('ChatGPTに接続中...');
235
- await navigateWithRetry(page, CHATGPT_CONFIG.DEFAULT_URL, { waitUntil: 'networkidle2' });
236
- // Wait for page to fully render (ChatGPT takes time to load UI)
237
- await new Promise((resolve) => setTimeout(resolve, 2000));
237
+ if (needsNavigation) {
238
+ await navigateWithRetry(page, CHATGPT_CONFIG.DEFAULT_URL, { waitUntil: 'networkidle2' });
239
+ // Wait for page to fully render (ChatGPT takes time to load UI)
240
+ await new Promise((resolve) => setTimeout(resolve, 2000));
241
+ }
242
+ else {
243
+ response.appendResponseLine('✅ 既存のChatGPTタブを再利用');
244
+ }
238
245
  // Step 2: Check if login is required (don't wait - stop immediately)
239
246
  const needsLogin = await isLoginRequired(page);
240
247
  if (needsLogin) {
@@ -368,25 +368,41 @@ export const askGeminiWeb = defineTool({
368
368
  return main?.innerText.slice(-5000) || '';
369
369
  });
370
370
  response.appendResponseLine('✅ 回答完了');
371
- // Save session
372
- if (isNewChat) {
373
- const chatUrl = page.url();
374
- const chatIdMatch = chatUrl.match(/\/app\/([a-f0-9]+)/);
375
- const chatId = chatIdMatch ? chatIdMatch[1] : 'unknown-' + Date.now();
371
+ // Always save/update session (not just for new chats)
372
+ const chatUrl = page.url();
373
+ const chatIdMatch = chatUrl.match(/\/app\/([a-f0-9]+)/);
374
+ const currentChatId = chatIdMatch ? chatIdMatch[1] : null;
375
+ if (currentChatId) {
376
+ // Check if URL changed (Gemini redirected to new chat)
377
+ const urlChanged = sessionChatId && currentChatId !== sessionChatId;
378
+ if (urlChanged) {
379
+ response.appendResponseLine(`⚠️ チャットIDが変更されました: ${sessionChatId} → ${currentChatId}`);
380
+ isNewChat = true;
381
+ }
382
+ // Load existing session to get conversation count
383
+ const sessions = await loadChatSessions();
384
+ const projectSessions = sessions[project] || [];
385
+ const existingSession = projectSessions.find(s => s.chatId === currentChatId);
386
+ const newCount = (existingSession?.conversationCount || 0) + 1;
376
387
  await saveChatSession(project, {
377
- chatId,
388
+ chatId: currentChatId,
378
389
  url: chatUrl,
379
390
  lastUsed: new Date().toISOString(),
380
- createdAt: new Date().toISOString(),
391
+ createdAt: existingSession?.createdAt || new Date().toISOString(),
381
392
  title: `[Project: ${project}]`,
382
- conversationCount: 1,
393
+ conversationCount: newCount,
383
394
  });
384
- sessionChatId = chatId;
395
+ sessionChatId = currentChatId;
385
396
  }
386
- // Save log
397
+ // Save log with conversation number
398
+ const finalSessions = await loadChatSessions();
399
+ const finalProjectSessions = finalSessions[project] || [];
400
+ const finalSession = finalProjectSessions.find(s => s.chatId === sessionChatId);
401
+ const conversationNumber = finalSession?.conversationCount || 1;
387
402
  const logPath = await saveConversationLog(project, sanitizedQuestion, responseText, {
388
403
  chatUrl: page.url(),
389
404
  chatId: sessionChatId,
405
+ conversationNumber,
390
406
  });
391
407
  response.appendResponseLine(`📝 会話ログ保存: ${logPath}`);
392
408
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-devtools-mcp-for-extension",
3
- "version": "0.22.2",
3
+ "version": "0.22.4",
4
4
  "description": "MCP server for Chrome extension development with Web Store automation. Fork of chrome-devtools-mcp with extension-specific tools.",
5
5
  "type": "module",
6
6
  "bin": "./scripts/cli.mjs",