Skip to content

Docusaurus 3.8 require Chrome browser #11204

Closed

Description

@nikolaymatrosov

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

I got the following error

[ERROR] Error: Command failed: ps cax -o command | grep -E "^(Google Chrome Canary|Google Chrome Dev|Google Chrome Beta|Google Chrome|Microsoft Edge|Brave Browser|Vivaldi|Chromium)$"

    at genericNodeError (node:internal/errors:983:15)
    at wrappedFn (node:internal/errors:537:14)
    at ChildProcess.exithandler (node:child_process:414:12)
    at ChildProcess.emit (node:events:524:28)
    at maybeClose (node:internal/child_process:1101:16)
    at Socket.<anonymous> (node:internal/child_process:456:11)
    at Socket.emit (node:events:524:28)
    at Pipe.<anonymous> (node:net:351:12) {
  code: 1,
  killed: false,
  signal: null,
  cmd: 'ps cax -o command | grep -E "^(Google Chrome Canary|Google Chrome Dev|Google Chrome Beta|Google Chrome|Microsoft Edge|Brave Browser|Vivaldi|Chromium)$"',
  stdout: '',
  stderr: ''
}

I don't have any of these browsers installed and I don't want to install any of them. I do have Safari on my Mac. Why don't you consider it as a suitable browser to open the Docusaurus?

Reproducible demo

No response

Steps to reproduce

Run npm run start on the computer where is only Safari or Firefox is installed.

Expected behavior

I can use my favorite browser.

Actual behavior

I got the error.

Your environment

  • Docusaurus version used: 3.8.0
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Safari, Node 22.13
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): MacOs

Self-service

  • I'd be willing to fix this bug myself.

Activity

  1. added
    bug
    status: needs triage
    on May 27, 2025
  2. slorber commented on May 27, 2025

    @slorber
    Collaborator

    Thanks for reporting, indeed, this is not expected to throw an error. You can bypass this with the --no-open CLI option.


    Why don't you consider it as a suitable browser to open the Docusaurus?

    We do consider Safari a suitable browser.

    The code producing this bug is a special handling for Chromium-based browsers on macOS. We didn't write it, it comes from Create-React-App. Since it was unmaintained and had performance issues, we internalized that code, and fixed the sync call perf bottleneck in #11007

    I don't know much about macOS / AppleScript, but this logic permits to "reuse" an existing localhost browser tab instead of opening a new one in Chrome. Maybe this is not possible to achieve for Safari? 🤷‍♂ We didn't write this part, just copy/pasted existing code.


    IMHO, the problem is just my integration that now prints an error message instead of swallowing it. I believe the error is not critical (does not crash the dev server), and also, isn't Safari opening like before? (not 100% sure)

  3. slorber commented on May 27, 2025

    @slorber
    Collaborator

    No you are right this error is blocking, and will be fixed in #11205


    Regarding doing the same as Chrome but for Safari (reusing the tab), I tried to port out AppleScript to work with Safari:

    property targetTab: null
    property targetTabIndex: -1
    property targetWindow: null
    property theProgram: "Safari"
    
    on run argv
      set theURL to item 1 of argv
    
      -- Allow requested program to be optional,
      -- default to Safari
      if (count of argv) > 1 then
        set theProgram to item 2 of argv
      end if
    
      using terms from application "Safari"
        tell application theProgram
    
          if (count of windows) = 0 then
            make new document
          end if
    
          -- 1: Looking for tab running debugger
          -- then, Reload debugging tab if found
          -- then return
          set found to my lookupTabWithUrl(theURL)
          if found then
            set current tab of targetWindow to targetTab
            tell targetTab to do JavaScript "location.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("about:blank")
          if found then
            set current tab of targetWindow to targetTab
            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
            set newTab to make new tab at end of tabs with properties {URL:theURL}
            set current tab to newTab
          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 "Safari"
        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

    It almost work but it looks like it's only possible to focus the tab by default, and not reload it like we do in Chrome.

    Unless the user configures their Safari DevTools accordingly to allow do JavaScrit to run.

    You must enable 'Allow JavaScript from Apple Events' in the Developer section of Safari Settings to use 'do JavaScript'. (8)

    I'm not sure we can really implement the same for Safari with a good DX, afaik there's no alternative to reload the Safari tab, and it's hard to teach users to configure their devtools for a marginal DX improvement.

    If anyone wants to work on this, please submit a PR, but I consider this quite low ROI.

  4. removed
    status: needs triage
    on May 27, 2025
  5. slorber commented on Jun 6, 2025

    @slorber
    Collaborator
  6. ilg-ul commented on Jul 15, 2025

    @ilg-ul
    Contributor

    There must be something wrong, I'm still getting this error on my Mac where I have no Chrome, even with the latest canary-6366:

    [INFO] Starting the development server...
    [WARNING] The `siteConfig.onBrokenMarkdownLinks` config option is deprecated and will be removed in Docusaurus v4.
    Please migrate and move this option to `siteConfig.markdown.hooks.onBrokenMarkdownLinks` instead.
    [SUCCESS] Docusaurus website is running at: http://localhost:3000/web-llvm/
    
    [ERROR] Error: spawn EBADF
        at ChildProcess.spawn (node:internal/child_process:421:11)
        at spawn (node:child_process:762:9)
        at Object.execFile (node:child_process:351:17)
        at exec (node:child_process:234:25)
        at node:child_process:243:21
        at getBrowsersToTry (/Users/ilg/MyProjects/xpack.github/docusaurus/web-llvm.git/website/node_modules/@docusaurus/core/lib/commands/utils/openBrowser/openBrowser.js:54:34)
        at /Users/ilg/MyProjects/xpack.github/docusaurus/web-llvm.git/website/node_modules/@docusaurus/core/lib/commands/utils/openBrowser/openBrowser.js:80:84
        at Object.async (/Users/ilg/MyProjects/xpack.github/docusaurus/web-llvm.git/website/node_modules/@docusaurus/logger/lib/perfLogger.js:42:47)
        at tryOpenWithAppleScript (/Users/ilg/MyProjects/xpack.github/docusaurus/web-llvm.git/website/node_modules/@docusaurus/core/lib/commands/utils/openBrowser/openBrowser.js:80:52)
        at /Users/ilg/MyProjects/xpack.github/docusaurus/web-llvm.git/website/node_modules/@docusaurus/core/lib/commands/utils/openBrowser/openBrowser.js:108:73
        at Object.async (/Users/ilg/MyProjects/xpack.github/docusaurus/web-llvm.git/website/node_modules/@docusaurus/logger/lib/perfLogger.js:42:47)
        at startBrowserProcess (/Users/ilg/MyProjects/xpack.github/docusaurus/web-llvm.git/website/node_modules/@docusaurus/core/lib/commands/utils/openBrowser/openBrowser.js:108:35)
        at openBrowser (/Users/ilg/MyProjects/xpack.github/docusaurus/web-llvm.git/website/node_modules/@docusaurus/core/lib/commands/utils/openBrowser/openBrowser.js:126:12)
        at doStart (/Users/ilg/MyProjects/xpack.github/docusaurus/web-llvm.git/website/node_modules/@docusaurus/core/lib/commands/start/start.js:44:41)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async Promise.all (index 0)
        at async runCLI (/Users/ilg/MyProjects/xpack.github/docusaurus/web-llvm.git/website/node_modules/@docusaurus/core/lib/commands/cli.js:56:5)
        at async file:///Users/ilg/MyProjects/xpack.github/docusaurus/web-llvm.git/website/node_modules/@docusaurus/core/bin/docusaurus.mjs:44:3 {
      errno: -9,
      code: 'EBADF',
      syscall: 'spawn'
    }
    [INFO] Docusaurus version: 3.8.1-canary-6366
    Node version: v20.18.0
    
     *  The terminal process "/bin/zsh '-l', '-c', 'npm run start'" terminated with exit code: 1. 
    

    If I manually patch openBrowser.js to skip await execPromise(command).catch(() => {...}), it no longer crashes.

    It looks like the catch() is not effective.

  7. slorber commented on Jul 15, 2025

    @slorber
    Collaborator

    The error looks different; it seems that your computer can't spawn a child process for unknown reasons. Maybe this happens just for you, and not others, hard to know why.

  8. ilg-ul commented on Jul 15, 2025

    @ilg-ul
    Contributor

    it seems that your computer can't spawn a child process for unknown reasons

    Right, for one reason or another, my Mac can't spawn the ps ... process, but I expected catch() to be triggered and recover from the error.

    I'll try to further investigate.

  9. slorber commented on Jul 15, 2025

    @slorber
    Collaborator

    It's possible that the library doesn't expect that from happening and is throwing the error synchronously instead of asynchronously.

    Try adding a try/catch in addition to the .catch() to see.

    That's also why we just got a new Promise.try() feature in ES: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/try

  10. ilg-ul commented on Jul 15, 2025

    @ilg-ul
    Contributor

    Try adding a try/catch in addition to the .catch() to see.

    Yes, that's what I planned to do.

  11. ilg-ul commented on Jul 15, 2025

    @ilg-ul
    Contributor

    I first patched the local code in openBrowser.js to read:

                const command = `ps cax -o command | grep -E "^(${supportedChromiumBrowsers.join('|')})$"`;
                const result = await execPromise(command).catch(() => {
                    console.log('original catch');
                    // Ignore grep errors when macOS user has no Chromium-based browser open
                    // See https://github.com/facebook/docusaurus/issues/11204
                });
                if (!result) {
                    console.log('empty')
                    return [];
                }
                console.log('result', result)

    I saw the [ERROR] Error: spawn EBADF... message reported before and none of my messages.

    Then I patched the code to read:

                const command = `ps cax -o command | grep -E "^(${supportedChromiumBrowsers.join('|')})$"`;
                let result = undefined // await execPromise(command).catch(() => {
                    // Ignore grep errors when macOS user has no Chromium-based browser open
                    // See https://github.com/facebook/docusaurus/issues/11204
                // });
                try {
                    result = await execPromise(command)
                } catch (err) {
                    console.log('catch', err)
                }
                if (!result) {
                    console.log('empty')
                    return [];
                }
                console.log('result', result)

    I saw the catch and empty messages.

    My JS knowledge is not deep enough to comment on the await ... catch() code correctness, but since the classical try ... catch seems functional, I would use it.

    It would be even better to diagnose why the execPromise() fails on macOS.

  12. slorber commented on Jul 17, 2025

    @slorber
    Collaborator

    @ilg-ul the execPromise doesn't fail on macOS, it fails for you specifically, probably due to something fancy you have locally that others don't. It works perfectly fine for me and if others had a similar problem, they would have reported. docusaurus start is commonly run by many macOS devs.

    We can't easily troubleshoot this; it's standard Node.js code.

    Maybe you can reproduce the problem outside of Docusaurus and report that as a Node.js issue:

    import {exec} from 'child_process';
    import {promisify} from 'util';
    
    const execPromise = promisify(exec);
    
    async function run() {
      await execPromise("ps cax -o command")
    }
    
    run();

    Anyway, we'll add an extra try/catch since it fixes the problem, but I'd rather not swallow the error message since it may hide a problem you have on your computer, so it's still nice to be aware of it even if a console log message might be annoying.

  13. ilg-ul commented on Jul 17, 2025

    @ilg-ul
    Contributor

    I did the following test:

    import { exec } from "child_process";
    import { promisify } from "util";
    
    const execPromise = promisify(exec);
    
    async function run() {
      const result = await execPromise("ps cax -o command");
      console.log(result.stdout);
    
      const command = 'ps cax -o command | grep Chrome';
      const result2 = await execPromise(command);
      console.log(result2.stdout);
    }
    
    run();

    The first call prints the (long) list of processes.

    The second fails with:

    Uncaught Error Error: Command failed: ps cax -o command | grep Chrome
        at genericNodeError (<node_internals>/internal/errors:984:15)
        at wrappedFn (<node_internals>/internal/errors:538:14)
        at exithandler (<node_internals>/child_process:422:12)
        at emit (<node_internals>/events:519:28)
        at maybeClose (<node_internals>/internal/child_process:1105:16)
        at <anonymous> (<node_internals>/internal/child_process:457:11)
        at emit (<node_internals>/events:519:28)
        at <anonymous> (<node_internals>/net:339:12)
        at callbackTrampoline (<node_internals>/internal/async_hooks:130:17)
    Process exited with code 1
    

    I took a long look at the error, but I can't tell what is wrong with it, the command runs just fine in a terminal.

    From the documentation it results that a sub-shell is used, so the pipe should not be a problem.

    I wonder what might be that fancy on my Mac to cause this?

  14. ilg-ul commented on Jul 17, 2025

    @ilg-ul
    Contributor

    Update:

    The error is cause by grep exiting with a non-zero.

    If I replace Chrome with Safari, the code no longer fails, and prints several process names that include Safari.

  15. slorber commented on Jul 17, 2025

    @slorber
    Collaborator

    The error you now get is different from EBADF

    Our source code contains the -E option: grep -E, which you removed. It should return exit code 0 with that option, even if no process with that name could be found.

  16. ilg-ul commented on Jul 17, 2025

    @ilg-ul
    Contributor

    With -E I get the same error:

    Uncaught Error Error: Command failed: ps cax -o command | grep -E Chrome
        at genericNodeError (<node_internals>/internal/errors:984:15)
        at wrappedFn (<node_internals>/internal/errors:538:14)
        at exithandler (<node_internals>/child_process:422:12)
        at emit (<node_internals>/events:519:28)
        at maybeClose (<node_internals>/internal/child_process:1105:16)
        at <anonymous> (<node_internals>/internal/child_process:457:11)
        at emit (<node_internals>/events:519:28)
        at <anonymous> (<node_internals>/net:339:12)
        at callbackTrampoline (<node_internals>/internal/async_hooks:130:17)
    

    As far as I know, -E means extended regexp.

  17. slorber commented on Jul 21, 2025

    @slorber
    Collaborator

    Ah yes, this is expected to fail actually, I added a comment in my source code:

          const result = await execPromise(command).catch(() => {
            // Ignore grep errors when macOS user has no Chromium-based browser open
            // See https://github.com/facebook/docusaurus/issues/11204
          });

    I'm not sure grep has any built-in way to return 0 exit code, but using || true in the command probably works.

    Anyway, it looks like you are not able to reproduce your [ERROR] Error: spawn EBADF initial error anymore?

    Since we swallow the grep exit code 1, maybe your local problem is now fixed?

  18. ilg-ul commented on Jul 21, 2025

    @ilg-ul
    Contributor

    The point here is not the error itself, but the confusing thing that the catch() does not actually catch the error and requires the execPromise() to be surrounded by the safer try ... catch().

    As for the EBADF, it might be a temporary side effect of a previous build of the huge LLVM project, that probably tries to start too many parallel actions, depleting the system resources.

    I think that regardless the size of the project, Docusaurus should limit the number of parallel actions to a reasonable value.

  19. slorber commented on Jul 24, 2025

    @slorber
    Collaborator

    The point here is not the error itself, but the confusing thing that the catch() does not actually catch the error and requires the execPromise() to be surrounded by the safer try ... catch().

    The .catch() does catch the error returned by grep.

    It only doesn't catch the EBADF error you got, which is different.

    I'll add an extra try/catch for v3.9, but I doubt this issue affects a lot of people apart from you temporarily. #11347

    As for the EBADF, it might be a temporary side effect of a previous build of the huge LLVM project, that probably tries to start too many parallel actions, depleting the system resources.

    I think that regardless the size of the project, Docusaurus should limit the number of parallel actions to a reasonable value.

    We already do in various places, but probably not everywhere. What kind of "parallel actions" do you have in mind?

    Why would a previous build affect docusaurus start if your previous build is not running anymore

  20. ilg-ul commented on Jul 24, 2025

    @ilg-ul
    Contributor

    I'll add an extra try/catch for v3.9

    Great, thank you!

    Docusaurus should limit the number of parallel actions to a reasonable value.
    We already do in various places, but probably not everywhere. What kind of "parallel actions" do you have in mind?

    I don't know the Docusaurus internals, but, according to my tests in other projects, the gain of running parallel actions that generate content in memory and then write it on disk is minimal with today very fast disks, but the memory consumption is linear with the number of actions. For the LLVM test project I reached more than 60 GB for 20K+ files, which is not reasonable. I'm convinced that if we could limit the number of parallel actions to some tens, the build would complete and the system would not trash.

    Parallelising actions that do network accesses is obviously beneficial, but the benefits of parallelising actions that do accesses on fast SSDs are debatable.

  21. slorber commented on Jul 24, 2025

    @slorber
    Collaborator

    We can't avoid loading all the data into memory. We have plugin lifecycles that receive that data, and changing the public API contract would be a breaking change for our whole plugin ecosystem.

    Also keep in mind that bundlers might have similar constraints: they need to load and see the whole module graph to bundle the final app.

    We cannot create the Docusaurus site "incrementally" by reading files one by one and building slices of the site; we need to feed the engine everything at once and let it build. That's a constraint we have for modern frontend experience. Tools not based on client-side navigations like Eleventy/Hugo and others can probably provide an incremental mode because they do not have these constraints of building a frontend app.

    At best, we could limit the parallelization when reading content files so that we don't read too many of them at once, but at the end of the day, we have to aggregate all the data we read in memory so that plugins and bundlers can see the whole picture.

  22. ilg-ul commented on Jul 24, 2025

    @ilg-ul
    Contributor

    I see.

    The doxygen2docusaurus converter also requires everything in memory, so all input XMLs, data model objects, view model objects, etc are in RAM. For the LLVM project there are probably ~300.000 class member definitions present at once. But the conversion takes a few minutes and uses a few GB of RAM. For the same content, a Docusaurus build went to 60GB+ and, after hours, it got stuck.

    I can imagine Docusaurus doing a lot more, but perhaps some improvements in memory management would be useful.

  23. slorber commented on Jul 24, 2025

    @slorber
    Collaborator

    Perf and memory improvements have been the focus of my work for the past months, and I've kinda exhausted all the low-hanging fruits I could find. If you have any idea how to improve things, contributions are welcome, but we need a concrete POC with a visible impact and not vague ideas. Also, some of these improvements could come from other places, such as our bundler Rspack, which also works on optimizations.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions