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

fix: Storybook does not respect BROWSER env var #21473

Merged
merged 5 commits into from
May 22, 2023
Merged
Changes from 3 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
21 changes: 18 additions & 3 deletions code/lib/core-server/src/utils/open-in-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@ import getDefaultBrowser from '@aw-web-design/x-default-browser';
import { dedent } from 'ts-dedent';

export function openInBrowser(address: string) {
const browserEnvVar = process.env.BROWSER;
const userBrowserIsChrome =
browserEnvVar === 'chrome' ||
browserEnvVar === 'chromium' ||
browserEnvVar === 'brave' ||
browserEnvVar === 'com.brave.browser';

const openOptions = browserEnvVar ? { app: { name: browserEnvVar } } : {};

getDefaultBrowser(async (err: any, res: any) => {
try {
if (res && (res.isChrome || res.isChromium || res.identity === 'com.brave.browser')) {
if (
res &&
(res.isChrome ||
res.isChromium ||
res.identity === 'com.brave.browser' ||
userBrowserIsChrome)
) {
// We use betterOpn for Chrome because it is better at handling which chrome tab
// or window the preview loads in.
betterOpn(address);
} else {
await open(address);
await open(address, openOptions);
}
} catch (error) {
logger.error(dedent`
Expand All @@ -22,4 +37,4 @@ export function openInBrowser(address: string) {
`);
}
});
}
}