Navigation failed because browser has disconnected
Learn how to fix the 'Navigation failed because browser has disconnected' error when the browser connection is lost during navigation

This error occurs when the browser connection is lost during navigation, typically due to browser crashes, network issues, or resource constraints. Let’s explore the causes and solutions.
Common Causes
- Browser crashes: Chrome process terminated unexpectedly
- Network issues: Connection problems during navigation
- Resource constraints: Insufficient memory or CPU
- Browser instability: Browser in an unstable state
- Multiple navigation attempts: Concurrent navigation causing conflicts
Solutions
1. Implement browser connection monitoring
async function launchBrowserWithMonitoring() {
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-dev-shm-usage'],
timeout: 30000
});
browser.on('disconnected', async () => {
console.log('Browser disconnected, attempting to reconnect...');
// Implement reconnection logic
});
return browser;
}
2. Add navigation retry logic
async function navigateWithRetry(page, url, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
if (!page.isConnected()) {
throw new Error('Browser disconnected');
}
await page.goto(url, {
waitUntil: 'networkidle0',
timeout: 30000
});
return;
} catch (error) {
if (i === maxRetries - 1) throw error;
console.log(`Retry ${i + 1} of ${maxRetries}`);
// Wait before retrying
await new Promise(resolve => setTimeout(resolve, 1000));
}
}
}
3. Implement browser recovery
async function runWithBrowserRecovery() {
let browser = await puppeteer.launch();
let page = await browser.newPage();
try {
await page.goto('https://example.com');
// ... your automation code ...
} catch (error) {
if (error.message.includes('browser has disconnected')) {
console.log('Browser disconnected, attempting recovery...');
// Clean up old browser
try { await browser.close(); } catch (e) {}
// Launch new browser
browser = await puppeteer.launch();
page = await browser.newPage();
await page.goto('https://example.com');
}
throw error;
}
}
4. Optimize browser launch options
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-dev-shm-usage',
'--disable-gpu',
'--disable-software-rasterizer',
'--disable-extensions',
'--disable-setuid-sandbox'
],
ignoreHTTPSErrors: true,
timeout: 30000
});
5. Implement connection health checks
async function checkBrowserHealth(browser) {
try {
const pages = await browser.pages();
if (pages.length === 0) {
throw new Error('No pages available');
}
return true;
} catch (error) {
console.log('Browser health check failed:', error);
return false;
}
}
// Usage
async function safeNavigation(page, url) {
const browser = page.browser();
if (!await checkBrowserHealth(browser)) {
throw new Error('Browser is not healthy');
}
await page.goto(url);
}
6. Handle browser process events
const browser = await puppeteer.launch();
process.on('SIGINT', async () => {
console.log('Received SIGINT, cleaning up...');
await browser.close();
process.exit(0);
});
process.on('uncaughtException', async (error) => {
console.error('Uncaught exception:', error);
await browser.close();
process.exit(1);
});
Still Encountering Issues?
If you’re still having trouble with browser disconnection errors, you can use a visual testing tool like Buglesstack to debug your automation and monitor browser stability.
try {
await page.goto('https://www.google.com/search?q=puppeteer');
await page.waitForSelector('[name="q"]');
}
catch (error) {
// Prepare buglesstack data
const buglesstackData = {
url: page.url(),
screenshot: await page.screenshot({ encoding: 'base64' }),
html: await page.content(),
metadata: {},
message: error.message,
stack: error.stack
};
// Get your access token from https://app.buglesstack.com
const ACCESS_TOKEN = 'HERE_YOUR_ACCESS_TOKEN';
// Send error to buglesstack
await axios.post('https://app.buglesstack.com/api/v1/crashes', buglesstackData, {
headers: {
Authorization: `Bearer ${ACCESS_TOKEN}`,
'Content-Type': 'application/json'
}
});
// Re-throw the error to propagate it
throw error;
}
By implementing proper browser connection management and recovery strategies, you can resolve the “Navigation failed because browser has disconnected” error and make your automation more resilient.