crw icon indicating copy to clipboard operation
crw copied to clipboard

Chrome tier: JS rendering fails with CDP -32602 "Target position can only be set for new windows"

Open magicprinc opened this issue 4 weeks ago • 2 comments

Summary

JS rendering via the Chrome/CDP tier fails on current Chrome (157.0.8103.39) in both embedded auto-spawn mode and against a configured ws_url endpoint. Every render attempt dies with:

Renderer error: CDP Target.createTarget: {"code":-32602,"message":"Target position can only be set for new windows"}

crw then falls back to plain HTTP ("warning": "js_escalation_failed: ..."), so SPA pages that need JS come back nearly empty. renderJs: true cannot force it either.

Environment

  • crw-mcp 0.42.1 (npm, win32-x64 binary, embedded/self-contained mode, no API key)
  • Windows 11 x64
  • Chrome 157.0.8103.39 (C:\Program Files\Google\Chrome\Application\chrome.exe)
  • Verified both paths:
    • auto-spawn (no renderer config — crw launches its own Chrome under %LOCALAPPDATA%\crw-mcp\chrome-profiles\...)
    • explicit endpoint via CRW_RENDERER__CHROME__WS_URL=ws://127.0.0.1:9222 (crw logs CDP renderer already configured — skipping auto-spawn)

Note: [renderer.chrome] ws_url in config.local.toml (and --config <file>) had no effect in this build — only the env var CRW_RENDERER__CHROME__WS_URL actually routed traffic. That may be a separate docs/config issue.

Reproduction

  1. Start Chrome with CDP:
    chrome --headless=new --remote-debugging-port=9222 --user-data-dir=C:\tmp\chrome-profile about:blank
    
  2. Start the MCP server with the endpoint configured:
    CRW_RENDERER__CHROME__WS_URL=ws://127.0.0.1:9222 crw-mcp
    
  3. Call crw_scrape on a JS-rendered page with renderJs: true, e.g. https://quotes.toscrape.com/js/.

Expected: metadata.renderedWith == "chrome" and the JS-injected quotes in the content.

Actual:

{
  "renderedWith": "http",
  "plainText": "Quotes to Scrape\nLogin",
  "warning": "js_escalation_failed: Renderer error: CDP Target.createTarget: {\"code\":-32602,\"message\":\"Target position can only be set for new windows\"}"
}

Root cause

Current Chrome rejects Target.createTarget when window bounds are passed without newWindow: true. Raw CDP against the same Chrome 157:

params result
{url:"about:blank"} ok, targetId returned
{url:"about:blank", width:1280, height:800} -32602 "Target position can only be set for new windows"
{url:"about:blank", left:10, top:10, width:1280, height:800, newWindow:false} -32602
{url:"about:blank", width:1280, height:800, newWindow:true} ok, targetId returned

So crw is sending viewport bounds in Target.createTarget without newWindow, which modern Chrome (157 tested; likely enforced since the corresponding Chrome change) refuses. Versions of Chrome that silently ignored the stray bounds hid this.

Suggested fix

Either is enough:

  1. Cheapest: set newWindow: true whenever bounds are passed. (Headless has no visible window, so this is harmless and preserves the requested viewport.)
  2. Cleaner: stop sending bounds in Target.createTarget entirely and apply the viewport with Emulation.setDeviceMetricsOverride on the attached session — no window management, works identically across Chrome versions and browserless-style backends.

Workaround currently in use

A local WebSocket proxy between crw and Chrome that adds newWindow: true (and drops left/top) on Target.createTarget, with everything else passed through byte-for-byte. With that in place the same call returns renderedWith: "chrome" and the JS content is present, so the rest of the Chrome tier works fine — this is purely the createTarget parameter shape.

Happy to test a patch build if useful.

magicprinc avatar Nov 08 '26 12:11 magicprinc

thanks for the really thorough report, the param table made this easy to confirm. reproduced it here on chrome 156 headless: bounds without newWindow get -32602, and adding newWindow: true keeps the 1280x2400 layout we ask for, including on headless-shell builds. a fix is on the way and i'll link the pr here.

the [renderer.chrome] ws_url in config.local.toml not taking effect for crw-mcp is a separate thing, i'll look at that one too.

us avatar Nov 09 '26 02:11 us

fixed in #705: the chrome tier now sends newWindow: true with the window size, so chrome 156+ accepts the target and renderJs renders again (checked against chrome 156 with ws_url: renderedWith: chrome, all 10 quotes on quotes.toscrape.com/js). it lands in the next crw-mcp release.

on the side note: you're right, crw-mcp only honours CRW_RENDERER__CHROME__WS_URL today. its browser auto-spawn overwrites a ws_url that comes from a config file. tracking that separately; the env var is the way until then.

us avatar Nov 09 '26 02:11 us