{"id":729,"url":"https://github.com/sindresorhus/open","last_synced_at":"2025-05-13T11:10:20.045Z","repository":{"id":15730972,"uuid":"18469325","full_name":"sindresorhus/open","owner":"sindresorhus","description":"Open stuff like URLs, files, executables. Cross-platform.","archived":false,"fork":false,"pushed_at":"2025-05-01T06:49:47.000Z","size":181,"stargazers_count":3285,"open_issues_count":57,"forks_count":255,"subscribers_count":29,"default_branch":"main","last_synced_at":"2025-05-13T11:09:59.408Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2014-04-05T15:14:11.000Z","updated_at":"2025-05-09T09:10:48.000Z","dependencies_parsed_at":"2024-01-19T11:32:59.309Z","dependency_job_id":"324d8926-21c7-4bfb-aefa-e8417beaf189","html_url":"https://github.com/sindresorhus/open","commit_stats":{"total_commits":192,"total_committers":54,"mean_commits":"3.5555555555555554","dds":"0.36458333333333337","last_synced_commit":"2ea66da8e8b20880d235447cf4c94ba275da6a5a"},"previous_names":["sindresorhus/opn"],"tags_count":66,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fopen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fopen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fopen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fopen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/open/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253929367,"owners_count":21985802,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:29.944Z","updated_at":"2025-05-13T11:10:20.012Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# open\n\n\u003e Open stuff like URLs, files, executables. Cross-platform.\n\nThis is meant to be used in command-line tools and scripts, not in the browser.\n\nIf you need this for Electron, use [`shell.openPath()`](https://www.electronjs.org/docs/api/shell#shellopenpathpath) instead.\n\nThis package does not make any security guarantees. If you pass in untrusted input, it's up to you to properly sanitize it.\n\n#### Why?\n\n- Actively maintained.\n- Supports app arguments.\n- Safer as it uses `spawn` instead of `exec`.\n- Fixes most of the original `node-open` issues.\n- Includes the latest [`xdg-open` script](https://gitlab.freedesktop.org/xdg/xdg-utils/-/blob/master/scripts/xdg-open.in) for Linux.\n- Supports WSL paths to Windows apps.\n\n## Install\n\n```sh\nnpm install open\n```\n\n**Warning:** This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and no longer provides a CommonJS export. If your project uses CommonJS, you will have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) or use the [dynamic `import()`](https://v8.dev/features/dynamic-import) function. Please don't open issues for questions regarding CommonJS / ESM.\n\n## Usage\n\n```js\nimport open, {openApp, apps} from 'open';\n\n// Opens the image in the default image viewer and waits for the opened app to quit.\nawait open('unicorn.png', {wait: true});\nconsole.log('The image viewer app quit');\n\n// Opens the URL in the default browser.\nawait open('https://sindresorhus.com');\n\n// Opens the URL in a specified browser.\nawait open('https://sindresorhus.com', {app: {name: 'firefox'}});\n\n// Specify app arguments.\nawait open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}});\n\n// Opens the URL in the default browser in incognito mode.\nawait open('https://sindresorhus.com', {app: {name: apps.browserPrivate}});\n\n// Open an app.\nawait openApp('xcode');\n\n// Open an app with arguments.\nawait openApp(apps.chrome, {arguments: ['--incognito']});\n```\n\n## API\n\nIt uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.\n\n### open(target, options?)\n\nReturns a promise for the [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process.\n\n#### target\n\nType: `string`\n\nThe thing you want to open. Can be a URL, file, or executable.\n\nOpens in the default app for the file type. For example, URLs opens in your default browser.\n\n#### options\n\nType: `object`\n\n##### wait\n\nType: `boolean`\\\nDefault: `false`\n\nWait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.\n\nNote that it waits for the app to exit, not just for the window to close.\n\nOn Windows, you have to explicitly specify an app for it to be able to wait.\n\n##### background \u003csup\u003e(macOS only)\u003c/sup\u003e\n\nType: `boolean`\\\nDefault: `false`\n\nDo not bring the app to the foreground.\n\n##### newInstance \u003csup\u003e(macOS only)\u003c/sup\u003e\n\nType: `boolean`\\\nDefault: `false`\n\nOpen a new instance of the app even it's already running.\n\nA new instance is always opened on other platforms.\n\n##### app\n\nType: `{name: string | string[], arguments?: string[]} | Array\u003c{name: string | string[], arguments: string[]}\u003e`\n\nSpecify the `name` of the app to open the `target` with, and optionally, app `arguments`. `app` can be an array of apps to try to open and `name` can be an array of app names to try. If each app fails, the last error will be thrown.\n\nThe app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use [`apps`](#apps) which auto-detects the correct binary to use.\n\nYou may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome.\n\nThe app `arguments` are app dependent. Check the app's documentation for what arguments it accepts.\n\n##### allowNonzeroExitCode\n\nType: `boolean`\\\nDefault: `false`\n\nAllow the opened app to exit with nonzero exit code when the `wait` option is `true`.\n\nWe do not recommend setting this option. The convention for success is exit code zero.\n\n### openApp(name, options?)\n\nOpen an app.\n\nReturns a promise for the [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process.\n\n#### name\n\nType: `string`\n\nThe app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use [`apps`](#apps) which auto-detects the correct binary to use.\n\nYou may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome.\n\n#### options\n\nType: `object`\n\nSame options as [`open`](#options) except `app` and with the following additions:\n\n##### arguments\n\nType: `string[]`\\\nDefault: `[]`\n\nArguments passed to the app.\n\nThese arguments are app dependent. Check the app's documentation for what arguments it accepts.\n\n### apps\n\nAn object containing auto-detected binary names for common apps. Useful to work around [cross-platform differences](#app).\n\n```js\nimport open, {apps} from 'open';\n\nawait open('https://google.com', {\n\tapp: {\n\t\tname: apps.chrome\n\t}\n});\n```\n\n`browser` and `browserPrivate` can also be used to access the user's default browser through [`default-browser`](https://github.com/sindresorhus/default-browser).\n\n#### Supported apps\n\n- [`chrome`](https://www.google.com/chrome) - Web browser\n- [`firefox`](https://www.mozilla.org/firefox) - Web browser\n- [`edge`](https://www.microsoft.com/edge) - Web browser\n- `browser` - Default web browser\n- `browserPrivate` - Default web browser in incognito mode\n\n`browser` and `browserPrivate` only supports `chrome`, `firefox`, and `edge`.\n\n## Related\n\n- [open-cli](https://github.com/sindresorhus/open-cli) - CLI for this module\n- [open-editor](https://github.com/sindresorhus/open-editor) - Open files in your editor at a specific line and column\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","JavaScript","目录","others","包","GIT 仓库","浏览器","Node","Libraries"],"sub_categories":["Miscellaneous","其他","工具库","运维\\\u0026DevOps","Desktop UI","杂项"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fopen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fopen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fopen/lists"}