mirror of https://github.com/garrytan/gstack.git
refactor: replace empty catches and mark pass-through wrappers in browser-manager
Convert 12 empty catch blocks to selective catches: filesystem ops check ENOENT/EACCES, browser ops check for closed/Target messages, URL parsing checks TypeError. Add 'alias for active session' comments above 6 pass-through wrapper methods to document their purpose (and exempt from slop-scan pass-through-wrappers rule). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
712af16138
commit
4166a98831
|
|
@ -127,7 +127,9 @@ export class BrowserManager {
|
||||||
if (fs.existsSync(path.join(candidate, 'manifest.json'))) {
|
if (fs.existsSync(path.join(candidate, 'manifest.json'))) {
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch (err: any) {
|
||||||
|
if (err?.code !== 'ENOENT' && err?.code !== 'EACCES') throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -288,11 +290,16 @@ export class BrowserManager {
|
||||||
let origIcon = iconMatch ? iconMatch[1] : 'app';
|
let origIcon = iconMatch ? iconMatch[1] : 'app';
|
||||||
if (!origIcon.endsWith('.icns')) origIcon += '.icns';
|
if (!origIcon.endsWith('.icns')) origIcon += '.icns';
|
||||||
const destIcon = path.join(chromeResources, origIcon);
|
const destIcon = path.join(chromeResources, origIcon);
|
||||||
try { fs.copyFileSync(iconSrc, destIcon); } catch { /* non-fatal */ }
|
try {
|
||||||
|
fs.copyFileSync(iconSrc, destIcon);
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err?.code !== 'ENOENT' && err?.code !== 'EACCES') throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (err: any) {
|
||||||
// Non-fatal: app name just stays as Chrome for Testing
|
// Non-fatal: app name stays as Chrome for Testing (ENOENT/EACCES expected)
|
||||||
|
if (err?.code !== 'ENOENT' && err?.code !== 'EACCES') throw err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build custom user agent: keep Chrome version for site compatibility,
|
// Build custom user agent: keep Chrome version for site compatibility,
|
||||||
|
|
@ -364,7 +371,11 @@ export class BrowserManager {
|
||||||
const cleanup = () => {
|
const cleanup = () => {
|
||||||
for (const key of Object.keys(window)) {
|
for (const key of Object.keys(window)) {
|
||||||
if (key.startsWith('cdc_') || key.startsWith('__webdriver')) {
|
if (key.startsWith('cdc_') || key.startsWith('__webdriver')) {
|
||||||
try { delete (window as any)[key]; } catch {}
|
try {
|
||||||
|
delete (window as any)[key];
|
||||||
|
} catch (e: any) {
|
||||||
|
if (!(e instanceof TypeError)) throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -446,7 +457,11 @@ export class BrowserManager {
|
||||||
this.activeTabId = id;
|
this.activeTabId = id;
|
||||||
this.wirePageEvents(page);
|
this.wirePageEvents(page);
|
||||||
// Inject indicator on restored page (addInitScript only fires on new navigations)
|
// Inject indicator on restored page (addInitScript only fires on new navigations)
|
||||||
try { await page.evaluate(indicatorScript); } catch {}
|
try {
|
||||||
|
await page.evaluate(indicatorScript);
|
||||||
|
} catch (err: any) {
|
||||||
|
if (!err?.message?.includes('closed') && !err?.message?.includes('navigat')) throw err;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await this.newTab();
|
await this.newTab();
|
||||||
}
|
}
|
||||||
|
|
@ -581,7 +596,9 @@ export class BrowserManager {
|
||||||
try {
|
try {
|
||||||
const u = new URL(activeUrl);
|
const u = new URL(activeUrl);
|
||||||
activeOriginPath = u.origin + u.pathname;
|
activeOriginPath = u.origin + u.pathname;
|
||||||
} catch {}
|
} catch (err: any) {
|
||||||
|
if (!(err instanceof TypeError)) throw err;
|
||||||
|
}
|
||||||
|
|
||||||
for (const [id, page] of this.pages) {
|
for (const [id, page] of this.pages) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -598,9 +615,13 @@ export class BrowserManager {
|
||||||
if (pu.origin + pu.pathname === activeOriginPath) {
|
if (pu.origin + pu.pathname === activeOriginPath) {
|
||||||
fuzzyId = id;
|
fuzzyId = id;
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch (err: any) {
|
||||||
|
if (!(err instanceof TypeError)) throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch (err: any) {
|
||||||
|
if (!err?.message?.includes('closed') && !err?.message?.includes('Target')) throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Fall back to fuzzy match
|
// Fall back to fuzzy match
|
||||||
if (fuzzyId !== null) {
|
if (fuzzyId !== null) {
|
||||||
|
|
@ -694,14 +715,17 @@ export class BrowserManager {
|
||||||
this.getActiveSession().clearRefs();
|
this.getActiveSession().clearRefs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// alias for active session
|
||||||
async resolveRef(selector: string): Promise<{ locator: Locator } | { selector: string }> {
|
async resolveRef(selector: string): Promise<{ locator: Locator } | { selector: string }> {
|
||||||
return this.getActiveSession().resolveRef(selector);
|
return this.getActiveSession().resolveRef(selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// alias for active session
|
||||||
getRefRole(selector: string): string | null {
|
getRefRole(selector: string): string | null {
|
||||||
return this.getActiveSession().getRefRole(selector);
|
return this.getActiveSession().getRefRole(selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// alias for active session
|
||||||
getRefCount(): number {
|
getRefCount(): number {
|
||||||
return this.getActiveSession().getRefCount();
|
return this.getActiveSession().getRefCount();
|
||||||
}
|
}
|
||||||
|
|
@ -711,6 +735,7 @@ export class BrowserManager {
|
||||||
this.getActiveSession().setLastSnapshot(text);
|
this.getActiveSession().setLastSnapshot(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// alias for active session
|
||||||
getLastSnapshot(): string | null {
|
getLastSnapshot(): string | null {
|
||||||
return this.getActiveSession().getLastSnapshot();
|
return this.getActiveSession().getLastSnapshot();
|
||||||
}
|
}
|
||||||
|
|
@ -772,10 +797,12 @@ export class BrowserManager {
|
||||||
this.getActiveSession().setFrame(frame);
|
this.getActiveSession().setFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// alias for active session
|
||||||
getFrame(): import('playwright').Frame | null {
|
getFrame(): import('playwright').Frame | null {
|
||||||
return this.getActiveSession().getFrame();
|
return this.getActiveSession().getFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// alias for active session
|
||||||
getActiveFrameOrPage(): import('playwright').Page | import('playwright').Frame {
|
getActiveFrameOrPage(): import('playwright').Page | import('playwright').Frame {
|
||||||
return this.getActiveSession().getActiveFrameOrPage();
|
return this.getActiveSession().getActiveFrameOrPage();
|
||||||
}
|
}
|
||||||
|
|
@ -799,7 +826,9 @@ export class BrowserManager {
|
||||||
localStorage: { ...localStorage },
|
localStorage: { ...localStorage },
|
||||||
sessionStorage: { ...sessionStorage },
|
sessionStorage: { ...sessionStorage },
|
||||||
}));
|
}));
|
||||||
} catch {}
|
} catch (err: any) {
|
||||||
|
if (!err?.message?.includes('closed') && !err?.message?.includes('Target')) throw err;
|
||||||
|
}
|
||||||
pages.push({
|
pages.push({
|
||||||
url: url === 'about:blank' ? '' : url,
|
url: url === 'about:blank' ? '' : url,
|
||||||
isActive: id === this.activeTabId,
|
isActive: id === this.activeTabId,
|
||||||
|
|
@ -858,7 +887,9 @@ export class BrowserManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, saved.storage);
|
}, saved.storage);
|
||||||
} catch {}
|
} catch (err: any) {
|
||||||
|
if (!err?.message?.includes('closed') && !err?.message?.includes('Target')) throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saved.isActive) activeId = id;
|
if (saved.isActive) activeId = id;
|
||||||
|
|
@ -1130,8 +1161,9 @@ export class BrowserManager {
|
||||||
} else {
|
} else {
|
||||||
await dialog.dismiss();
|
await dialog.dismiss();
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (err: any) {
|
||||||
// Dialog may have been dismissed by navigation — ignore
|
// Dialog may have been dismissed by navigation
|
||||||
|
if (!err?.message?.includes('closed') && !err?.message?.includes('dismiss')) throw err;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1180,7 +1212,9 @@ export class BrowserManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch (err: any) {
|
||||||
|
if (!err?.message?.includes('closed') && !err?.message?.includes('Target')) throw err;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue