fix(browser): support Termux Android scenarios (#1655)
* fix(browser): support Termux Android scenarios * fix(build): lock Termux artifact generation * ci(android): add manual Termux browser smoke verification --------- Co-authored-by: tyloryang <[邮箱]> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
tyloryang <[邮箱]>
morluto
parent
890dfa49f6
commit
87edf14940
@@ -8,7 +8,12 @@ import {
|
||||
PlaywrightScenarioBrowserCleanupOwner,
|
||||
} from "./PlaywrightScenarioBrowser.js";
|
||||
|
||||
afterEach(() => vi.unstubAllEnvs());
|
||||
const hostPlatform = process.platform;
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
Object.defineProperty(process, "platform", { value: hostPlatform });
|
||||
});
|
||||
|
||||
it("locks one attached browser for spellings that discover the same endpoint", () => {
|
||||
expect(attachedScenarioLeaseKey("http://127.0.0.1:9222", "page-1")).toBe(
|
||||
@@ -73,6 +78,43 @@ it("passes the selected environment to the actual browser launch boundary", asyn
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps Termux execution support when launching Chromium on Android", async () => {
|
||||
Object.defineProperty(process, "platform", { value: "android" });
|
||||
vi.stubEnv("PREFIX", "/data/data/com.termux/files/usr");
|
||||
const selected = { LANG: "selected-language", PREFIX: process.env.PREFIX };
|
||||
let launchOptions: Parameters<
|
||||
typeof import("playwright-core").chromium.launchPersistentContext
|
||||
>[1];
|
||||
const scenario = browserScenarioSchema.parse({
|
||||
browser: { mode: "launch", executable_path: process.execPath },
|
||||
start_url: { url: "https://example.test" },
|
||||
actions: [
|
||||
{ step_id: "settle", action: "wait_for_timeout", duration_ms: 1 },
|
||||
],
|
||||
});
|
||||
|
||||
await expect(
|
||||
openPlaywrightScenarioBrowser(scenario, selected, {
|
||||
launcher: {
|
||||
connectOverCDP: async () => {
|
||||
throw new Error("Unexpected connection");
|
||||
},
|
||||
launchPersistentContext: async (_profile, options) => {
|
||||
launchOptions = options;
|
||||
throw new Error("launch boundary reached");
|
||||
},
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow("launch boundary reached");
|
||||
|
||||
expect(launchOptions?.args).toEqual(["--no-sandbox", "--single-process"]);
|
||||
expect(launchOptions?.env).toEqual({
|
||||
LANG: "selected-language",
|
||||
LD_PRELOAD: "/data/data/com.termux/files/usr/lib/libtermux-exec.so",
|
||||
TERMUX_EXEC__PROC_SELF_EXE: process.execPath,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps attached-target ownership until cancelled cleanup actually settles", async () => {
|
||||
const controller = new AbortController();
|
||||
const closeStarted = deferred<void>();
|
||||
|
||||
@@ -273,13 +273,26 @@ const allowedBrowserEnvironment = (
|
||||
"XAUTHORITY",
|
||||
"XDG_RUNTIME_DIR",
|
||||
];
|
||||
return Object.fromEntries(
|
||||
const selected = Object.fromEntries(
|
||||
allowed
|
||||
.map((name) => [name, environment[name]] as const)
|
||||
.filter(
|
||||
(entry): entry is readonly [string, string] => entry[1] !== undefined,
|
||||
),
|
||||
);
|
||||
if (process.platform !== "android") return selected;
|
||||
|
||||
// Android rejects execve() for binaries below Termux's application data
|
||||
// directory. Termux supplies an exec interceptor that rewrites those calls
|
||||
// through the system linker and removes itself for the launched program.
|
||||
// Playwright must retain it for its Chromium child process.
|
||||
const prefix = environment.PREFIX;
|
||||
if (prefix === undefined) return selected;
|
||||
return {
|
||||
...selected,
|
||||
LD_PRELOAD: `${prefix}/lib/libtermux-exec.so`,
|
||||
TERMUX_EXEC__PROC_SELF_EXE: process.execPath,
|
||||
};
|
||||
};
|
||||
const findConnectedPage = async (
|
||||
browser: Pick<Browser, "contexts">,
|
||||
@@ -495,6 +508,13 @@ export const openPlaywrightScenarioBrowser = async (
|
||||
handleSIGINT: false,
|
||||
handleSIGTERM: false,
|
||||
timeout: 0,
|
||||
// Termux's Chromium cannot create its renderer process through Android's
|
||||
// executable boundary. Single-process mode keeps the browser and page in
|
||||
// the Termux-launched process so scenario navigation remains available.
|
||||
args:
|
||||
process.platform === "android"
|
||||
? ["--no-sandbox", "--single-process"]
|
||||
: [],
|
||||
});
|
||||
} catch (cause: unknown) {
|
||||
const cleanup = () =>
|
||||
|
||||
Reference in New Issue
Block a user