supapup
Version:
⚡ Lightning-fast MCP browser dev tool. Navigate → Get instant structured data. No screenshots needed! Puppeteer: 📸 → CSS selectors → JS eval. Supapup: semantic IDs ready to use. 10x faster, 90% fewer tokens.
82 lines (81 loc) • 2.33 kB
JavaScript
export class BrowserRecovery {
state = {
browser: null,
page: null,
isHealthy: true,
crashCount: 0
};
constructor() { }
async checkBrowserHealth(browser, page) {
if (!browser || !page) {
return false;
}
try {
// Quick health check - try to get the URL
await page.evaluate(() => window.location.href);
return true;
}
catch (error) {
// Browser is likely crashed or in bad state
return false;
}
}
async cleanupCrashedBrowser(browser) {
if (!browser)
return;
try {
// Try to close gracefully first
await browser.close();
}
catch (error) {
// Force kill if graceful close fails
try {
const pages = await browser.pages();
for (const page of pages) {
try {
await page.close();
}
catch (e) {
// Ignore individual page close errors
}
}
}
catch (e) {
// Even getting pages might fail
}
// Last resort - disconnect
try {
browser.disconnect();
}
catch (e) {
// Ignore disconnect errors
}
}
}
recordCrash(error) {
this.state.crashCount++;
this.state.lastError = error;
this.state.lastCrashTime = new Date();
this.state.isHealthy = false;
}
resetState() {
this.state.browser = null;
this.state.page = null;
this.state.isHealthy = true;
}
getCrashInfo() {
return {
crashCount: this.state.crashCount,
lastError: this.state.lastError,
lastCrashTime: this.state.lastCrashTime
};
}
shouldThrottle() {
// If more than 3 crashes in 5 minutes, suggest throttling
if (this.state.crashCount > 3 && this.state.lastCrashTime) {
const fiveMinutesAgo = new Date(Date.now() - 5 * 60 * 1000);
return this.state.lastCrashTime > fiveMinutesAgo;
}
return false;
}
}