Fall back when optional GeoIP setup fails

This commit is contained in:
Pradeep Elankumaran
2026-09-08 22:36:29 -07:00
parent 9120ee49d5
commit f8bdac71ec
2 changed files with 39 additions and 1 deletions
+24 -1
View File
@@ -1077,6 +1077,25 @@ function _countActiveHandles() {
try { return process._getActiveHandles().length; } catch { return null; }
}
function isCamoufoxGeoipError(err) {
return /Invalid locale:|GeoLite|MaxMind|geolocation/i.test(err?.message || String(err || ''));
}
async function buildLaunchOptionsWithGeoipFallback(baseOptions, attemptMeta) {
try {
return await launchOptions(baseOptions);
} catch (err) {
if (!baseOptions.geoip || !isCamoufoxGeoipError(err)) {
throw err;
}
log('warn', 'camoufox geoip setup failed; retrying launch options without geoip', {
...attemptMeta,
error: err.message,
});
return await launchOptions({ ...baseOptions, geoip: false });
}
}
async function launchBrowserInstance() {
const hostOS = getHostOS();
const maxAttempts = proxyPool?.launchRetries ?? 1;
@@ -1123,7 +1142,7 @@ async function launchBrowserInstance() {
excludeAddons: ['UBO'],
});
}
const options = await launchOptions({
const options = await buildLaunchOptionsWithGeoipFallback({
executable_path: externalCamoufox?.executablePath,
headless: useVirtualDisplay ? false : !useDesktopWindow,
os: hostOS,
@@ -1133,6 +1152,10 @@ async function launchBrowserInstance() {
geoip: !!launchProxy,
virtual_display: vdDisplay,
exclude_addons: CONFIG.disableDefaultAddons ? ['UBO'] : undefined,
}, {
attempt,
proxyServer: launchProxy?.server || null,
proxySession: launchProxy?.sessionId || null,
});
options.proxy = normalizePlaywrightProxy(options.proxy);
// Playwright's launcher defaults handleSIGTERM/SIGINT/SIGHUP to true,
+15
View File
@@ -60,6 +60,21 @@ describe('launch compatibility source contract', () => {
expect(launch).toContain('headless: useVirtualDisplay ? false : !useDesktopWindow');
});
test('falls back when optional GeoIP setup is unavailable', () => {
const geoipFallback = sourceBetween(
'function isCamoufoxGeoipError',
'async function launchBrowserInstance()'
);
const launchBrowser = sourceBetween(
'async function launchBrowserInstance()',
'async function ensureBrowser()'
);
expect(geoipFallback).toMatch(/GeoLite\|MaxMind\|geolocation/);
expect(geoipFallback).toContain('geoip: false');
expect(launchBrowser).toContain('buildLaunchOptionsWithGeoipFallback');
});
test('health probe context also uses a null viewport', () => {
const healthProbeOptions = sourceBetween(
'testContext = await browser.newContext(',