# karagoz open-url

Opens a URL, such as a deep link or a web link, in the app the system picks or in the app you name.

Runs on

- Android emulator
- Android device
- iOS simulator
- iOS device

## Usage

```console title="~/app"
karagoz open-url <url> [--app <id>] [--device <id>]
```

A deep link looks like `myapp://item/42`.

## Before you start

- On an iOS simulator: Xcode, opened once.
- On an iPhone: Xcode 15 or newer, paired with the Mac, Developer Mode on (Settings > Privacy & Security > Developer Mode).

## Options

| Option          | Default                                                               | Meaning                                                                                               |
| --------------- | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `<url>`         |                                                                       | The URL. It needs a scheme (`https:`, `myapp:`); nothing else is checked before the device gets it.   |
| `--app <id>`    | none: the system picks the app                                        | The package name of the app that gets the URL, such as `com.android.chrome`. Not on an iOS simulator. |
| `--device <id>` | see [Device selection](https://karagozmcp.com/docs/device-selection/) |                                                                                                       |

## Examples

```console title="~/app"
$ karagoz open-url https://example.com
{"device":"emulator-5554","url":"https://example.com"}
```

## Output

```json
{
  "device": "emulator-5554",
  "url": "https://example.com"
}
```

- `device` string: The adb serial, or the simulator's or iPhone's UDID.
- `url` string: The URL as given.
- `app` string: Only when `--app` was given: the package name or bundle id from `--app`.

## Errors

| Code                                                                                | When                                                                                                                                                                                                                 |
| ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`INVALID_ARGS`](https://karagozmcp.com/docs/error-codes/#invalid-args)             | `'<url>' is not a URL: it needs a scheme such as https: or myapp:`, or `--app`'s `'<value>' is not a package name`, as for [`launch`](https://karagozmcp.com/docs/commands/launch/). Checked before any device call. |
| [`APP_NOT_FOUND`](https://karagozmcp.com/docs/error-codes/#app-not-found)           | Without `--app`: `no app on emulator-5554 opens 'nosuchscheme://x'`. With it: `package 'dev.karagoz.nope' is not installed on emulator-5554`.                                                                        |
| [`APP_NOT_LAUNCHABLE`](https://karagozmcp.com/docs/error-codes/#app-not-launchable) | `package 'com.android.shell' has no activity that opens 'myapp://x'`. The app is installed but declares nothing for this URL.                                                                                        |
| [`ADB_FAILED`](https://karagozmcp.com/docs/error-codes/#adb-failed)                 | Android refused the start. The message is Android's `Error:` line.                                                                                                                                                   |
| [`ADB_TIMEOUT`](https://karagozmcp.com/docs/error-codes/#adb-timeout)               | After 30 s, as for `launch`.                                                                                                                                                                                         |

Every call can also get the [device selection errors](https://karagozmcp.com/docs/device-selection/#errors) and the adb errors.

## Notes

- The URL reaches the app as given, including `&`, `#`, `;`, quotes and spaces. The caller quotes it only for its own shell.
- Exit `0` means Android started an activity for the URL, not that the app handled it. Read the [tree](https://karagozmcp.com/docs/commands/ui-tree/) to check.
- With two apps for the URL and no default set, Android shows its chooser and `open-url` exits `0`.
- An `https` URL opens the app that owns the domain only when that app is verified for it. Otherwise the browser opens it.
- `open-url` never restarts the app. If it is in front, the URL goes to the running app.

## On an iOS simulator

Runs `simctl openurl`. With `--app` it returns [`NOT_SUPPORTED`](https://karagozmcp.com/docs/error-codes/#not-supported): `an iOS simulator opens a URL only in the app the system picks; run open-url without --app`.

```json
{
  "device": "2EC769C1-2EF2-47EB-A441-E6843968F039",
  "url": "https://example.com"
}
```

- It returns before the app is in front: Safari took 1.3 to 2.2 s from a cold start.
- For an app’s own scheme, iOS first asks `Open in “<app>”?` with Cancel and Open. The app gets the URL only after you tap Open: [`tap --text Open`](https://karagozmcp.com/docs/commands/tap/).
- `APP_NOT_FOUND`: `no app on <udid> opens 'nosuchscheme://x'`. Any other refusal is [`SIMCTL_FAILED`](https://karagozmcp.com/docs/error-codes/#simctl-failed) with simctl’s message.

## On an iPhone

Without `--app`, runs `devicectl device process openURL`. With it, runs `devicectl device process launch --payload-url`, with `--app` the bundle id.

- `APP_NOT_FOUND`: `no app on <UDID> opens 'nosuchscheme://x'` without `--app`, `app 'dev.karagoz.nope' is not installed on <UDID>` with it.
- A locked iPhone gives [`DEVICE_NOT_READY`](https://karagozmcp.com/docs/error-codes/#device-not-ready).
- Any other refusal is [`DEVICECTL_FAILED`](https://karagozmcp.com/docs/error-codes/#devicectl-failed) with devicectl’s description and the phone’s reason.

## MCP equivalent

MCP equivalent `open_url {"url":"https://example.com"}` [MCP tools](https://karagozmcp.com/docs/mcp/#tools)

Arguments: `url` (required), `app`, `device`. The names are the CLI's option and positional names.

## Related commands

- [karagoz ui-tree](https://karagozmcp.com/docs/commands/ui-tree/): Read the tree after the call to check that the app handled the URL.
- [karagoz launch](https://karagozmcp.com/docs/commands/launch/): Checks `--app` as a package name the same way, and times out the same way.
- [karagoz tap](https://karagozmcp.com/docs/commands/tap/): Tap Open on the iOS prompt for an app's own scheme.
