Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to replay launch #272

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/replay/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ async function commandUploadRecording(id: string, opts: CommandLineOptions) {

async function commandLaunchBrowser(
url: string | undefined,
opts: Pick<CommandLineOptions, "warn"> & {
opts: Pick<CommandLineOptions, "warn" | "directory"> & {
browser: string | undefined;
attach: boolean | undefined;
}
Expand All @@ -208,7 +208,7 @@ async function commandLaunchBrowser(

const attach = opts.attach || false;

await launchBrowser(browser, [url || "about:blank"], attach);
await launchBrowser(browser, [url || "about:blank"], attach, { ...opts, verbose: true });
process.exit(0);
} catch (e) {
console.error("Failed to launch browser");
Expand Down
6 changes: 3 additions & 3 deletions packages/replay/src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function getPlatformKey(browserName: BrowserName): PlatformKeys | undefined {
return undefined;
}

function getExecutablePath(browserName: BrowserName) {
function getExecutablePath(browserName: BrowserName, opts?: Options) {
const overridePathKey = `REPLAY_${browserName.toUpperCase()}_EXECUTABLE_PATH`;
const overridePath = process.env[overridePathKey];
if (overridePath) {
Expand All @@ -156,7 +156,7 @@ function getExecutablePath(browserName: BrowserName) {
}

const executablePathParts = EXECUTABLE_PATHS[key];
return executablePathParts ? path.join(getRuntimesDirectory(), ...executablePathParts) : null;
return executablePathParts ? path.join(getRuntimesDirectory(opts), ...executablePathParts) : null;
}

/**
Expand Down Expand Up @@ -199,7 +199,7 @@ async function installReplayBrowser(
force = false,
opts: Options = {}
) {
const replayDir = getDirectory();
const replayDir = getDirectory(opts);
const browserDir = getRuntimesDirectory(opts);
const dstDir = path.join(browserDir, dstName);
const dstExists = fs.existsSync(dstDir);
Expand Down
17 changes: 12 additions & 5 deletions packages/replay/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,16 +776,20 @@ async function updateMetadata({
async function launchBrowser(
browserName: BrowserName,
args: string[] = [],
attach: boolean = false
attach: boolean = false,
opts?: Options
) {
const execPath = getExecutablePath(browserName);
const execPath = getExecutablePath(browserName, opts);
if (!execPath) {
throw new Error(`${browserName} not supported on the current platform`);
}

await ensureBrowsersInstalled(browserName, false);
if (!fs.existsSync(execPath)) {
maybeLog(opts?.verbose, `Installing ${browserName}`);
await ensureBrowsersInstalled(browserName, false, opts);
}

const profileDir = path.join(getDirectory(), "runtimes", "profiles", browserName);
const profileDir = path.join(getDirectory(opts), "runtimes", "profiles", browserName);

const browserArgs: Record<BrowserName, string[]> = {
chromium: [
Expand All @@ -797,7 +801,10 @@ async function launchBrowser(
firefox: ["-foreground", ...args],
};

const proc = spawn(execPath, browserArgs[browserName], { detached: !attach });
const proc = spawn(execPath, browserArgs[browserName], {
detached: !attach,
env: { ...process.env, RECORD_REPLAY_DIRECTORY: opts?.directory },
});
proc.unref();

return proc;
Expand Down
Loading