Skip to content

Stealth Chromium that passes every bot detection test. Drop-in Playwright replacement with source-level fingerprint patches. 50+ tests passed.

fix(license): surface license exits on Puppeteer and .NET launch failures (#584)

CloakHQ3c7f1ac84368
diff --git a/dotnet/src/CloakBrowser/CloakLauncher.cs b/dotnet/src/CloakBrowser/CloakLauncher.cs
index 9a94bfb..c0fb446 100644
--- a/dotnet/src/CloakBrowser/CloakLauncher.cs
+++ b/dotnet/src/CloakBrowser/CloakLauncher.cs
@@ -68,7 +68,7 @@ public static class CloakLauncher
catch (Exception ex)
{
playwright.Dispose();
- var lic = License.LicenseErrorFrom(ex);
+ var lic = License.LicenseErrorFrom(ex, denialPath);
if (lic is not null) throw lic;
throw;
}
@@ -216,7 +216,7 @@ public static class CloakLauncher
catch (Exception ex)
{
playwright.Dispose();
- var lic = License.LicenseErrorFrom(ex);
+ var lic = License.LicenseErrorFrom(ex, denialPath);
if (lic is not null) throw lic;
throw;
}
diff --git a/dotnet/src/CloakBrowser/License.cs b/dotnet/src/CloakBrowser/License.cs
index df0ec64..02d165e 100644
--- a/dotnet/src/CloakBrowser/License.cs
+++ b/dotnet/src/CloakBrowser/License.cs
@@ -136,10 +136,14 @@ public static class License
/// <summary>
/// Returns a <see cref="CloakBrowserLicenseError"/> if a launch failure was a
/// license deny, else null so the original exception propagates unchanged.
+ /// Falls back to the launch's denial file: .NET Playwright's launch failure
+ /// carries no exit code in its message ("Target ... has been closed").
/// </summary>
- public static CloakBrowserLicenseError? LicenseErrorFrom(Exception ex)
+ public static CloakBrowserLicenseError? LicenseErrorFrom(Exception ex, string? denialPath = null)
{
var msg = LicenseErrorMessage(ex.Message);
+ if (msg is null && denialPath is not null && ReadDenialFile(denialPath) is int code)
+ LicenseExitMessages.TryGetValue(code, out msg);
return msg is not null ? new CloakBrowserLicenseError(msg, ex) : null;
}
diff --git a/dotnet/tests/CloakBrowser.Tests/LicenseTests.cs b/dotnet/tests/CloakBrowser.Tests/LicenseTests.cs
index 28314b0..e2a84b1 100644
--- a/dotnet/tests/CloakBrowser.Tests/LicenseTests.cs
+++ b/dotnet/tests/CloakBrowser.Tests/LicenseTests.cs
@@ -1099,6 +1099,40 @@ public class LicenseTests : IDisposable
Assert.Null(License.LicenseErrorFrom(new Exception("some unrelated crash")));
}
+ [Fact]
+ public void LicenseErrorFrom_FallsBackToDenialFile()
+ {
+ // .NET Playwright's real launch failure on an over-cap seat carries no exit
+ // code (#584); the binary's denial file is the only source.
+ var dir = Directory.CreateTempSubdirectory("cb-denial-").FullName;
+ try
+ {
+ var f = Path.Combine(dir, "launch.json");
+ File.WriteAllText(f, "76");
+ var original = new Exception("Target page, context or browser has been closed");
+ var lic = License.LicenseErrorFrom(original, f);
+ Assert.NotNull(lic);
+ Assert.Contains("session limit", lic!.Message);
+ Assert.Same(original, lic.InnerException);
+ }
+ finally { Directory.Delete(dir, true); }
+ }
+
+ [Fact]
+ public void LicenseErrorFrom_NoFileOrNonLicenseCode_ReturnsNull()
+ {
+ var dir = Directory.CreateTempSubdirectory("cb-denial-").FullName;
+ try
+ {
+ var closed = new Exception("Target page, context or browser has been closed");
+ Assert.Null(License.LicenseErrorFrom(closed, Path.Combine(dir, "absent.json")));
+ var f = Path.Combine(dir, "crash.json");
+ File.WriteAllText(f, "139");
+ Assert.Null(License.LicenseErrorFrom(closed, f));
+ }
+ finally { Directory.Delete(dir, true); }
+ }
+
// ── post-handshake denial: helpers + guard ────────────
[Theory]
diff --git a/js/src/license.ts b/js/src/license.ts
index d009fe4..53be1cf 100644
--- a/js/src/license.ts
+++ b/js/src/license.ts
@@ -79,10 +79,11 @@ const LICENSE_EXIT_MESSAGES: Record<number, string> = {
};
// Playwright embeds the child-process exit as "<process did exit: exitCode=N, ...>".
-// Puppeteer surfaces it as "Browser process exited with code N" / "with exit code N".
+// Puppeteer 25.x surfaces it as "Failed to launch the browser process: Code: N".
// Anchored so an unrelated "exitCode=" elsewhere in the error can't false-match.
const EXIT_CODE_PATTERNS = [
/process did exit:\s*exitCode=(\d+)/,
+ /Failed to launch the browser process:\s*Code:\s*(\d+)/,
/exited with (?:exit )?code (\d+)/i,
];
@@ -105,12 +106,18 @@ export function licenseErrorMessage(errorText: string): string | null {
/**
* Return a CloakBrowserLicenseError if a launch failure was a license deny,
- * else null so the original error propagates unchanged.
+ * else null so the original error propagates unchanged. Falls back to the
+ * launch's denial file because not every driver puts the exit code in its
+ * error text (.NET Playwright reports only "Target ... has been closed").
*/
-export function licenseErrorFrom(err: unknown): CloakBrowserLicenseError | null {
+export function licenseErrorFrom(err: unknown, denialPath?: string): CloakBrowserLicenseError | null {
const text = err instanceof Error ? err.message : String(err);
const msg = licenseErrorMessage(text);
- return msg !== null ? new CloakBrowserLicenseError(msg, { cause: err }) : null;
+ if (msg !== null) return new CloakBrowserLicenseError(msg, { cause: err });
+ if (!denialPath) return null;
+ const code = readDenialFile(denialPath);
+ const fromFile = code !== null ? LICENSE_EXIT_MESSAGES[code] : undefined;
+ return fromFile ? new CloakBrowserLicenseError(fromFile, { cause: err }) : null;
}
// Env var the wrapper uses to tell the Pro binary where to record a license
diff --git a/js/src/playwright.ts b/js/src/playwright.ts
index d9a68ab..360b851 100644
--- a/js/src/playwright.ts
+++ b/js/src/playwright.ts
@@ -201,7 +201,7 @@ export async function launch(options: LaunchOptions = {}): Promise<Browser> {
launchOptions = await buildLaunchOptions(options, denialPath);
browser = await chromium.launch(launchOptions);
} catch (err) {
- const lic = licenseErrorFrom(err);
+ const lic = licenseErrorFrom(err, denialPath);
if (lic) throw lic;
throw err;
}
@@ -399,7 +399,7 @@ export async function launchPersistentContext(
...envResult,
});
} catch (err) {
- const lic = licenseErrorFrom(err);
+ const lic = licenseErrorFrom(err, denialPath);
if (lic) throw lic;
throw err;
}
diff --git a/js/src/puppeteer.ts b/js/src/puppeteer.ts
index d4f48d5..6efedfc 100644
--- a/js/src/puppeteer.ts
+++ b/js/src/puppeteer.ts
@@ -210,7 +210,7 @@ export async function launch(options: LaunchOptions = {}): Promise<Browser> {
...envResult,
});
} catch (err) {
- const lic = licenseErrorFrom(err);
+ const lic = licenseErrorFrom(err, denialPath);
if (lic) throw lic;
throw err;
}
@@ -277,7 +277,7 @@ export async function launchPersistentContext(
...envResult,
});
} catch (err) {
- const lic = licenseErrorFrom(err);
+ const lic = licenseErrorFrom(err, denialPath);
if (lic) throw lic;
throw err;
}
diff --git a/js/tests/license.test.ts b/js/tests/license.test.ts
index 98f1ebe..104b915 100644
--- a/js/tests/license.test.ts
+++ b/js/tests/license.test.ts
@@ -808,8 +808,11 @@ describe("license exit-code surfacing", () => {
const playwrightText = (code: number) =>
"BrowserType.launch: Target page, context or browser has been closed\n" +
`Browser logs:\n- [pid=123] <process did exit: exitCode=${code}, signal=null>`;
+ // Verbatim shape from puppeteer-core 25.12 (@puppeteer/browsers launch.ts), as in #584.
const puppeteerText = (code: number) =>
- `Failed to launch the browser process!\nBrowser process exited with code ${code}`;
+ `Failed to launch the browser process: Code: ${code}\n\nstderr:\n` +
+ "[3105:3105:1011/003330.769964:ERROR:media/gpu/vaapi/vaapi_wrapper.cc:1801] vaInitialize failed: unknown libva error\n\n" +
+ "TROUBLESHOOTING: https://pptr.dev/troubleshooting\n";
it.each([
[76, "session limit"],
@@ -823,7 +826,7 @@ describe("license exit-code surfacing", () => {
expect(msg!.startsWith("CloakBrowser Pro:")).toBe(true);
});
- it("maps the Puppeteer 'exited with code N' phrasing", () => {
+ it("maps the Puppeteer 'Code: N' launch-failure phrasing", () => {
expect(licenseErrorMessage(puppeteerText(76))).toContain("session limit");
expect(licenseErrorMessage(puppeteerText(77))).toContain("invalid");
});
@@ -847,6 +850,28 @@ describe("license exit-code surfacing", () => {
expect(lic!.message).toContain("invalid");
expect(licenseErrorFrom(new Error("some unrelated crash"))).toBeNull();
});
+
+ it("licenseErrorFrom falls back to the denial file when the text has no code", () => {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "cb-denial-"));
+ const f = path.join(dir, "launch.json");
+ fs.writeFileSync(f, "76");
+ const original = new Error("Target page, context or browser has been closed");
+ const lic = licenseErrorFrom(original, f);
+ expect(lic).toBeInstanceOf(CloakBrowserLicenseError);
+ expect(lic!.message).toContain("session limit");
+ expect(lic!.cause).toBe(original);
+ fs.rmSync(dir, { recursive: true, force: true });
+ });
+
+ it("licenseErrorFrom returns null with no file or a non-license code in it", () => {
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "cb-denial-"));
+ const closed = new Error("Target page, context or browser has been closed");
+ expect(licenseErrorFrom(closed, path.join(dir, "absent.json"))).toBeNull();
+ const f = path.join(dir, "crash.json");
+ fs.writeFileSync(f, "139");
+ expect(licenseErrorFrom(closed, f)).toBeNull();
+ fs.rmSync(dir, { recursive: true, force: true });
+ });
});
// ── getActiveSessionCount ─────────────────────────────