Skip to content

Commit

Permalink
Merge pull request #21473 from thtliife/next
Browse files Browse the repository at this point in the history
fix: Storybook does not respect BROWSER env var
  • Loading branch information
ndelangen authored May 22, 2023
2 parents a8f4dce + 25700a2 commit 7ed98c7
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 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 Down

0 comments on commit 7ed98c7

Please sign in to comment.