How to Open a URL in a Specific Browser
Launch any URL in Chrome, Edge, Firefox, Safari, or another browser from Windows, macOS, Linux, scripts, and web apps.
Use the browser’s own launcher when you need a specific browser. Pass the URL to that browser’s executable or operating-system launcher. Default-browser commands such as xdg-open, open, and Windows start intentionally use the configured default application.
Replace https://example.com in the examples below with your destination.
Quick command reference
| System | Specific browser | Default browser |
|---|---|---|
| Windows | start "" "microsoft-edge:https://example.com" or an executable path |
start "" "https://example.com" |
| macOS | open -a "Google Chrome" "https://example.com" |
open "https://example.com" |
| Linux | firefox "https://example.com", google-chrome "https://example.com", or chromium "https://example.com" |
xdg-open "https://example.com" |
Windows
Open a URL in Microsoft Edge
start "" "microsoft-edge:https://example.com"
Windows documents the microsoft-edge: URI scheme for launching Edge with a specified URL. The empty quoted argument after start is the window title; without it, a quoted URL can be misinterpreted as the title.
Open a URL in Chrome, Firefox, or another installed browser
Run the browser executable and pass the URL as a separate argument:
"C:\Program Files\Google\Chrome\Application\chrome.exe" "https://example.com"
"C:\Program Files\Mozilla Firefox\firefox.exe" "https://example.com"
Installation paths vary. Check the browser shortcut’s Target field, search the Start menu, or locate the executable under Program Files and Program Files (x86). If the executable is on PATH, its short command may work:
chrome "https://example.com"
firefox "https://example.com"
Open the default browser
start "" "https://example.com"
Windows associates http: and https: with the user’s default browser. Ordinary applications generally cannot choose which registered application handles those schemes. See Microsoft Learn for Windows URI activation documentation.
Windows batch and PowerShell
:: Command Prompt or .bat
start "" "microsoft-edge:https://example.com"
# PowerShell
Start-Process "microsoft-edge:https://example.com"
Start-Process "C:\Program Files\Google\Chrome\Application\chrome.exe" -ArgumentList "https://example.com"
Quote both the executable and URL. Treat URLs as data, especially when they come from users; validate the scheme and avoid concatenating untrusted text into shell commands.
macOS
Choose a browser by application name
open -a "Google Chrome" "https://example.com"
open -a Safari "https://example.com"
open -a Firefox "https://example.com"
open -a asks Launch Services to open the URL with the named application. The name must match the installed app, including spaces. You can inspect installed applications in Finder’s Applications folder.
Use the default browser
open "https://example.com"
Shell scripts
#!/usr/bin/env bash
set -eu
url="https://example.com"
open -a "Google Chrome" "$url"
Always quote the variable so query strings, fragments, ampersands, and spaces are passed as one argument.
Linux
Launch a named browser
firefox "https://example.com"
google-chrome "https://example.com"
chromium "https://example.com"
The executable name depends on your distribution and package. Use command -v firefox, command -v google-chrome, or command -v chromium to see whether a command is available.
Use the preferred browser
xdg-open "https://example.com"
The freedesktop.org xdg-open manual defines this as opening a URL in the user’s preferred application, normally the configured default browser.
Linux scripts
#!/usr/bin/env bash
set -eu
url="https://example.com"
firefox "$url"
In a headless SSH session, a graphical browser may fail because there is no display. Use an active desktop session, set the appropriate display environment, or use a browser automation or screenshot service instead.
Opening a URL from application code
Python
import platform
import subprocess
import webbrowser
url = "https://example.com"
# Default browser on every supported desktop OS.
webbrowser.open(url)
# Explicit browser examples:
if platform.system() == "Darwin":
subprocess.Popen(["open", "-a", "Google Chrome", url])
elif platform.system() == "Windows":
subprocess.Popen(["C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe", url])
else:
subprocess.Popen(["firefox", url])
webbrowser.open follows the platform’s browser registration and is therefore best for the default browser. Use subprocess when you control the executable and need a named browser.
Node.js
import { spawn } from "node:child_process";
const url = "https://example.com";
const platform = process.platform;
if (platform === "darwin") {
spawn("open", ["-a", "Google Chrome", url], { detached: true });
} else if (platform === "win32") {
spawn("cmd", ["/c", "start", "", "microsoft-edge:" + url], { detached: true });
} else {
spawn("firefox", [url], { detached: true });
}
Pass arguments as an array rather than building a shell command. This preserves URL characters and reduces shell-injection risk.
cURL cannot open a desktop browser
cURL makes HTTP requests; it does not launch a graphical browser. Use the operating-system commands above when you need a visible browser window. Use cURL when you need to fetch a page or call a rendering API.
Can a website force a link to open in a particular browser?
Usually, no. A normal https:// link is handled by the visitor’s default browser. A website cannot silently select Chrome instead of Edge or Safari for an ordinary link.
Protocol handlers are a narrower mechanism. An installed application or progressive web app can register a custom scheme such as web+music:. The browser asks the user to approve or choose a handler, then navigates to the registered URL template. The MDN registerProtocolHandler documentation describes this flow. It does not provide unlimited control over arbitrary ordinary links.
Choosing the right method
| Need | Use | Trade-off |
|---|---|---|
| Open once in a named browser | Browser executable, open -a, or Edge’s URI scheme |
You must know the installed app or executable |
| Respect the user’s default | start, open, xdg-open, or Python webbrowser |
You cannot choose the browser |
| Launch from a script | Argument-based process APIs | Handle platform differences and missing installations |
| Open from a website | Regular HTTPS link or approved protocol handler | The user or operating system controls the handler |
| Capture a page without a desktop | Screenshot API or headless automation | Requires an API or browser runtime |
Edge cases
- URLs with query strings: quote the complete URL so
&is not interpreted by the shell. - Fragments: pass
#sectionas part of the quoted URL. Fragments are handled locally by the browser and are not sent in the HTTP request. - Existing browser windows: browsers may reuse an existing process and profile. A launcher command does not guarantee a new window or clean session.
- Private browsing: use browser-specific flags such as Chrome’s
--incognitoor Firefox’s--private-windowonly when your deployment policy permits them. - Multiple installations: call the full executable path when stable selection matters.
- Remote or headless machines: a launcher needs a graphical session. For unattended rendering, use browser automation or a screenshot API.
- Custom URL schemes: schemes such as
mailto:and registered application protocols use their own handlers and may prompt for consent.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Windows opens the wrong app | You used an ordinary HTTPS URL | Use microsoft-edge: for Edge or the browser executable path. |
start opens a blank window |
The quoted URL was treated as the window title | Use start "" "https://example.com". |
| “Command not found” on Linux | The package is absent or executable has another name | Run command -v, install the browser, or use its full path. |
| macOS says the application cannot be found | The app name does not match | Check Applications and pass the exact name to open -a. |
| Nothing appears over SSH | No graphical display is available | Run in a desktop session or use headless automation/API rendering. |
| URL is truncated or split | Shell metacharacters were not quoted | Quote the URL and pass process arguments as an array. |
| Link always opens the default browser | A website cannot force a named browser | Launch locally with an OS command or install and register a custom protocol handler. |
Performance, reliability, and security
- Launching an already-running browser is usually faster than starting a new profile, but reuse can carry cookies, extensions, and tabs.
- Full executable paths are more reliable for scheduled jobs; application names and short commands depend on installation and
PATH. - Check the process exit status and log failures in automation. A successful launch only means the process was started, not that the page loaded.
- Validate allowed URL schemes before launching user-provided input. Prefer argument arrays over shell interpolation.
- For repeatable screenshots, isolate the browser profile, set a fixed viewport, wait for the page’s readiness condition, and control cookies and authentication explicitly.
Or skip the browser setup
If your goal is a screenshot rather than a visible browser window, ScreenshotNeo returns a PNG, JPEG, WebP, or PDF from one request. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Cookie and consent banners, newsletter popups, and chat widgets are removed before the shot. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. ScreenshotNeo also provides an MCP server so Claude, Cursor, and other MCP clients can take screenshots. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Create a free ScreenshotNeo account.
FAQ
How do I open a link in Chrome instead of Edge?
On Windows, run Chrome’s executable with the URL. On macOS, use open -a "Google Chrome" "URL". On Linux, use google-chrome "URL" or the installed executable name.
What command opens Firefox from Command Prompt?
Run Firefox’s full executable path followed by the quoted URL, for example "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "https://example.com".
How do I open Safari from a script?
Use open -a Safari "https://example.com".
Does xdg-open select a browser?
No. It opens the user’s preferred application. Call a browser executable when you need a specific choice.
Can JavaScript choose the visitor’s browser?
No for ordinary HTTPS links. A registered protocol handler can receive a custom scheme after user consent, but it is not a general browser-forcing mechanism.


