Skip to content

Commit 34328fa

Browse files
fix(browser): an origin's scheme is read in lower case
An origin named HTTPS://... passed the check but its WebSocket form came out as ws://HTTPS://...; the origin is now rebuilt from its parsed parts, scheme in lower case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f5c1600 commit 34328fa

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎packages/agentenv-protocol/src/agentenv_protocol/website_browser/environment.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,9 @@ def _mode() -> str:
670670

671671

672672
def _origin(value: Any) -> str:
673-
"""``value`` as an origin a CDP address is minted under: an http or https URL, a path allowed, with no query,
674-
fragment or credentials; InvalidArgument for anything else."""
673+
"""``value`` as an origin a CDP address is minted under, its scheme in lower case as the address's WebSocket form
674+
reads it: an http or https URL, a path allowed, with no query, fragment or credentials; InvalidArgument for anything
675+
else."""
675676
try:
676677
parts = urlsplit(value)
677678
valid = (value.isprintable() and parts.scheme in ("http", "https") and bool(parts.hostname)
@@ -681,7 +682,7 @@ def _origin(value: Any) -> str:
681682
valid = False
682683
if not valid:
683684
raise InvalidArgument("origin is an http or https URL with no query, fragment or credentials")
684-
return value
685+
return f"{parts.scheme}://{parts.netloc}{parts.path}"
685686

686687

687688
def _parsed(model: type[BaseModel], items: Any, what: str) -> list:

‎packages/agentenv-protocol/tests/test_browser_cdp.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ async def call(method, params=None, *, session_id=None, timeout_s=None):
376376
ada = (await http.post("/agentenv/ext/browser/cdp", json={"user": "ada", "origin": "https://t.tunnel.test/"},
377377
headers=BEHIND_TLS)).json()
378378
bob = (await http.post("/agentenv/ext/browser/cdp", json={"user": "bob"}, headers=BEHIND_TLS)).json()
379+
cy = (await http.post("/agentenv/ext/browser/cdp", json={"user": "cy", "origin": "HTTPS://t.tunnel.test"},
380+
headers=BEHIND_TLS)).json()
379381
paths = [address["http_url"].split("/svc/chromium", 1)[1] for address in (ada, bob)]
380382
seen = [(await http.get(f"{path}json/version", headers=BEHIND_TLS)).json()["webSocketDebuggerUrl"]
381383
for path in paths]
@@ -385,6 +387,8 @@ async def call(method, params=None, *, session_id=None, timeout_s=None):
385387
"ws_url": f"wss://t.tunnel.test/svc/chromium/cdp/{token}/devtools/browser"}
386388
assert seen[0] == ada["ws_url"]
387389
assert bob["ws_url"].startswith("ws://t.tunnel.test/") and seen[1] == bob["ws_url"]
390+
assert cy["http_url"].startswith("https://t.tunnel.test/svc/chromium/cdp/")
391+
assert cy["ws_url"].startswith("wss://t.tunnel.test/svc/chromium/cdp/")
388392

389393

390394
@pytest.mark.asyncio

0 commit comments

Comments
 (0)