MCPcopy
hub / github.com/AgentDeskAI/browser-tools-mcp / discoverServer

Function discoverServer

chrome-extension/panel.js:656–921  ·  view source on GitHub ↗
(quietMode = false)

Source from the content-addressed store, hash-verified

654
655// Server discovery function (extracted to be reusable)
656async function discoverServer(quietMode = false) {
657 // Cancel any ongoing discovery operations before starting a new one
658 cancelOngoingDiscovery();
659
660 // Create a new AbortController for this discovery process
661 discoveryController = new AbortController();
662 isDiscoveryInProgress = true;
663
664 // In quiet mode, we don't show the connection status until we either succeed or fail completely
665 if (!quietMode) {
666 connectionStatusDiv.style.display = "block";
667 statusIcon.className = "status-indicator";
668 statusText.textContent = "Discovering server...";
669 }
670
671 // Always update the connection banner
672 updateConnectionBanner(false, null);
673
674 try {
675 console.log("Starting server discovery process");
676
677 // Add an early cancellation listener that will respond to page navigation/refresh
678 discoveryController.signal.addEventListener("abort", () => {
679 console.log("Discovery aborted via AbortController signal");
680 isDiscoveryInProgress = false;
681 });
682
683 // Common IPs to try (in order of likelihood)
684 const hosts = ["localhost", "127.0.0.1"];
685
686 // Add the current configured host if it's not already in the list
687 if (
688 !hosts.includes(settings.serverHost) &&
689 settings.serverHost !== "0.0.0.0"
690 ) {
691 hosts.unshift(settings.serverHost); // Put at the beginning for priority
692 }
693
694 // Add common local network IPs
695 const commonLocalIps = ["192.168.0.", "192.168.1.", "10.0.0.", "10.0.1."];
696 for (const prefix of commonLocalIps) {
697 for (let i = 1; i <= 5; i++) {
698 // Reduced from 10 to 5 for efficiency
699 hosts.push(`${prefix}${i}`);
700 }
701 }
702
703 // Build port list in a smart order:
704 // 1. Start with current configured port
705 // 2. Add default port (3025)
706 // 3. Add sequential ports around the default (for fallback detection)
707 const ports = [];
708
709 // Current configured port gets highest priority
710 const configuredPort = parseInt(settings.serverPort, 10);
711 ports.push(configuredPort);
712
713 // Add default port if it's not the same as configured

Callers 3

panel.jsFile · 0.70
createConnectionBannerFunction · 0.70
scheduleReconnectAttemptFunction · 0.70

Calls 4

cancelOngoingDiscoveryFunction · 0.85
updateConnectionBannerFunction · 0.85
tryServerConnectionFunction · 0.85
scheduleReconnectAttemptFunction · 0.85

Tested by

no test coverage detected