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

[Bug]: better-opn is bundled and therefore openChrome.applescript is missing. #29123

Closed
clintandrewhall opened this issue Sep 13, 2024 · 1 comment · Fixed by #29137
Closed

Comments

@clintandrewhall
Copy link
Contributor

Describe the bug

As titled. Setting OPEN_MATCH_HOST_ONLY has no effect, as better-opn always fails.

Logging the error within better-opn:

e Error: Command failed: osascript ../openChrome.applescript "http://localhost:6006/" "http://localhost:6006" "Google Chrome"
    at genericNodeError (node:internal/errors:984:15)
    at wrappedFn (node:internal/errors:538:14)
    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at startBrowserProcess (/Users/clint/Projects/clintandrewhall.com/node_modules/@storybook/core/dist/core-server/index.cjs:42243:51)
    at m8.exports (/Users/clint/Projects/clintandrewhall.com/node_modules/@storybook/core/dist/core-server/index.cjs:42272:16)
    at /Users/clint/Projects/clintandrewhall.com/node_modules/@storybook/core/dist/core-server/index.cjs:47275:107
    at W6.exports (/Users/clint/Projects/clintandrewhall.com/node_modules/@storybook/core/dist/core-server/index.cjs:41908:122) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 48538,
  stdout: null,
  stderr: null
}

Script missing from ../:

Screenshot 2024-09-13 at 12 18 17 PM

Fix

Placing openChrome.applescript in the root of core-server fixes the issue. But I doubt this is what you'd want to do.

Reproduction link

https://storybook.js.org

Reproduction steps

  1. Setup storybook launch script with cross-env in package.json:

"storybook": "cross-env BROWSER=\"google chrome\" OPEN_MATCH_HOST_ONLY=true storybook dev -p 6006"

  1. Run yarn storybook - browser tab is not reused.

Fix:

  1. Paste openChrome.applescript to node_modules/@storybook/core/dist/openChrome.applescript
  2. Run yarn storybook - browser tab is reused.

System

Storybook Environment Info:

  System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M2
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    Yarn: 4.4.1 - ~/.nvm/versions/node/v20.12.2/bin/yarn <----- active
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
  Browsers:
    Chrome: 128.0.6613.138
    Safari: 17.5
  npmPackages:
    @storybook/addon-essentials: ^8.2.8 => 8.3.0
    @storybook/addon-interactions: ^8.2.8 => 8.3.0
    @storybook/addon-links: ^8.2.8 => 8.3.0
    @storybook/blocks: ^8.2.8 => 8.3.0
    @storybook/react: ^8.2.8 => 8.3.0
    @storybook/react-vite: ^8.2.8 => 8.3.0
    @storybook/test: ^8.2.8 => 8.3.0
    chromatic: ^11.8.0 => 11.10.0
    eslint-plugin-storybook: ^0.8.0 => 0.8.0
    storybook: ^8.2.8 => 8.3.0
    storybook-addon-remix-react-router: ^3.0.0 => 3.0.0

Additional context

No response

@clintandrewhall clintandrewhall changed the title [Bug]: better-opn is bundled and therefore openChrome.applescript is missing. [Bug]: better-opn is bundled and therefore openChrome.applescript is missing. Sep 13, 2024
@clintandrewhall
Copy link
Contributor Author

clintandrewhall commented Sep 13, 2024

Confirmed: patching the package fixes the issue.

.yarn/patches/@storybook-core-npm-8.3.0-833013f32e.patch:

diff --git a/dist/openChrome.applescript b/dist/openChrome.applescript
new file mode 100644
index 0000000..e69de29
@@ -1,94 +0,0 @@
-(*
-Copyright (c) 2015-present, Facebook, Inc.
-This source code is licensed under the MIT license found in the
-LICENSE file in the root directory of this source tree.
-*)
-
-property targetTab: null
-property targetTabIndex: -1
-property targetWindow: null
-property theProgram: "Google Chrome"
-
-on run argv
-  set theURL to item 1 of argv
-  set matchURL to item 2 of argv
-
-  -- Allow requested program to be optional,
-  -- default to Google Chrome
-  if (count of argv) > 2 then
-    set theProgram to item 3 of argv
-  end if
-
-  using terms from application "Google Chrome"
-    tell application theProgram
-
-      if (count every window) = 0 then
-        make new window
-      end if
-
-      -- 1: Looking for tab running debugger
-      -- then, Reload debugging tab if found
-      -- then return
-      set found to my lookupTabWithUrl(matchURL)
-      if found then
-        set targetWindow's active tab index to targetTabIndex
-        tell targetTab to reload
-        tell targetWindow to activate
-        set index of targetWindow to 1
-        return
-      end if
-
-      -- 2: Looking for Empty tab
-      -- In case debugging tab was not found
-      -- We try to find an empty tab instead
-      set found to my lookupTabWithUrl("chrome://newtab/")
-      if found then
-        set targetWindow's active tab index to targetTabIndex
-        set URL of targetTab to theURL
-        tell targetWindow to activate
-        return
-      end if
-
-      -- 3: Create new tab
-      -- both debugging and empty tab were not found
-      -- make a new tab with url
-      tell window 1
-        activate
-        make new tab with properties {URL:theURL}
-      end tell
-    end tell
-  end using terms from
-end run
-
--- Function:
--- Lookup tab with given url
--- if found, store tab, index, and window in properties
--- (properties were declared on top of file)
-on lookupTabWithUrl(lookupUrl)
-  using terms from application "Google Chrome"
-    tell application theProgram
-      -- Find a tab with the given url
-      set found to false
-      set theTabIndex to -1
-      repeat with theWindow in every window
-        set theTabIndex to 0
-        repeat with theTab in every tab of theWindow
-          set theTabIndex to theTabIndex + 1
-          if (theTab's URL as string) contains lookupUrl then
-            -- assign tab, tab index, and window to properties
-            set targetTab to theTab
-            set targetTabIndex to theTabIndex
-            set targetWindow to theWindow
-            set found to true
-            exit repeat
-          end if
-        end repeat
-
-        if found then
-          exit repeat
-        end if
-      end repeat
-    end tell
-  end using terms from
-  return found
-end lookupTabWithUrl
\ No newline at end of file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants