Skip to content

stagehand-python@4.5.0a0.dev1729

@shrey150 shrey150 tagged this 20 Nov 22:55
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
# why

`browse open example.com` fails with `-32000 Cannot navigate to invalid
URL` because CDP rejects bare hosts without a scheme. This is part of
the `open unexpected` failure bucket (8,139 fails, 1,462 installs over
14 days; open is used by 765 users/day, 60% of CLI DAU). Agents often
pass bare hosts like `example.com` or `localhost:3000`.

# what changed

Adds `normalizeUrlScheme()` in `packages/cli/src/lib/normalize-url.ts`
that prefixes a scheme when the argument looks like a bare host:
- `https://` for domains (e.g. `example.com`) and non-localhost IPs
- `http://` for `localhost` and `127.0.0.1`

Leaves everything else unchanged so invalid URLs still fail downstream.

```bash
# before (main)
$ browse open example.com --local --headless
-32000 Cannot navigate to invalid URL

# after (this branch)
$ browse open example.com --local --headless
{
  "title": "Example Domain",
  "url": "https://example.com/"
}
```

# test plan

- [x] Unit tests for `normalizeUrlScheme` covering `example.com`,
`localhost:3000`, `127.0.0.1:8080/x`, `about:blank`, `file:///x`, and
`not a url`: **13 passed**
- [x] Full CLI test suite: **709 passed**
- [x] Lint and type check: passed
- [x] Manual verification with local Chrome (output above)
<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-dccdc6ad-37a8-53a2-8254-6905f59a8216?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-dccdc6ad-37a8-53a2-8254-6905f59a8216&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Fixes `browse open` crashing when given a bare-host URL like
`example.com` or `localhost:3000`. Previously CDP rejected these with
`-32000 Cannot navigate to invalid URL`; now the URL is normalized
before navigation by prefixing `https://` for domains and non-localhost
IPs, and `http://` for `localhost` and `127.0.0.1`. Host extraction is
case-insensitive and handles query strings and paths. URLs that already
have a scheme or don't look like a host are left unchanged, so invalid
input still fails downstream.

<sup>Written for commit 41d7a3d2144666aba2330b9bddcfd768757d0a05.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/browserbase/stagehand/pull/3512?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="View guided diff"
src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>
<a
href="https://www.cubic.dev/action/auto-fix/pr/browserbase/stagehand/3512?returnTo=https%3A%2F%2Fgithub.com%2Fbrowserbase%2Fstagehand%2Fpull%2F3512&source=description"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img
alt="Turn on auto-fix"
src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Assets 2
Loading