Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c5be7e9

Browse files
added more error handling for finding localhost tab
1 parent 5dafcf3 commit c5be7e9

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

‎src/extension/background.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,30 @@ function isLocalhost(url) {
2020

2121
// Helper function to find localhost tab
2222
async function findLocalhostTab() {
23-
const tabs = await chrome.tabs.query({ currentWindow: true });
24-
return tabs.find((tab) => tab.url && isLocalhost(tab.url));
23+
try {
24+
// First check current window
25+
const currentWindowTabs = await chrome.tabs.query({ currentWindow: true });
26+
const localhostTab = currentWindowTabs.find((tab) => tab.url && isLocalhost(tab.url));
27+
28+
if (localhostTab) {
29+
return localhostTab;
30+
}
31+
32+
// If not found in current window, check all windows
33+
const allTabs = await chrome.tabs.query({});
34+
const localhostTabAnyWindow = allTabs.find((tab) => tab.url && isLocalhost(tab.url));
35+
36+
if (localhostTabAnyWindow) {
37+
// Focus the window containing the localhost tab
38+
await chrome.windows.update(localhostTabAnyWindow.windowId, { focused: true });
39+
return localhostTabAnyWindow;
40+
}
41+
42+
return null;
43+
} catch (error) {
44+
console.error('Error finding localhost tab:', error);
45+
return null;
46+
}
2547
}
2648

2749
//keep alive functionality to address port disconnection issues
@@ -329,13 +351,22 @@ async function getActiveTab() {
329351
return localhostTab.id;
330352
}
331353

354+
// If no localhost tab is found, provide a more informative error
355+
const errorMessage =
356+
'No localhost tab found. Please ensure:\n' +
357+
'1. A React development server is running\n' +
358+
'2. The server is using localhost\n' +
359+
'3. The development page is open in Chrome';
360+
361+
console.warn(errorMessage);
362+
332363
// Fallback to current active tab
333364
const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
334365
if (tabs.length > 0) {
335366
return tabs[0].id;
336367
}
337368

338-
throw new Error('No active tab');
369+
throw new Error(errorMessage);
339370
} catch (error) {
340371
console.error('Error in getActiveTab:', error);
341372
throw error;

‎src/extension/build/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Reactime",
3-
"version": "26.0",
3+
"version": "26.1",
44
"devtools_page": "devtools.html",
55
"description": "A Chrome extension for time travel debugging and performance monitoring in React applications.",
66
"manifest_version": 3,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /