Commit 041b92a
authored
fix(stagehand): Inject
## Summary
The scheduled e2e tests for the Stagehand template have failed for
several days. After PR #1900 fixed the `OPENAI_API_KEY` propagation, the
next layer of failure surfaced — every Stagehand variant in [today's
run](https://github.com/apify/crawlee-python/actions/runs/26136278735)
failed identically on the Apify platform with:
```
stagehand.InternalServerError: Error code: 500 - {'success': False, 'message': 'connect ECONNREFUSED 127.0.0.1:<port>'}
```
## Root cause
Reproduced locally inside the `apify/actor-python-playwright:3.13`
image: Stagehand's `BrowserLaunchOptions` accepts a `chromium_sandbox`
field, but the field is **not propagated** to the underlying Chromium
launch. When the actor runs as root (which it does on Apify), Chromium
silently refuses to start because the setuid sandbox can't initialise —
and Stagehand's local SEA server then hits `ECONNREFUSED` when it tries
to connect to the missing Chromium CDP port. The regular
`PlaywrightCrawler` is unaffected because Playwright's Python binding
*does* translate `chromium_sandbox=False` into `--no-sandbox`.
## Fix
In `StagehandBrowserPlugin`, when the sandbox is disabled
(`config.disable_browser_sandbox=True`, which Apify auto-sets), append
`'--no-sandbox'` to `browser_launch_options['args']` as an explicit
workaround. Verified end-to-end in the same actor base image — the
crawler now completes requests successfully.
The `apify push` hang from the same scheduled run is a separate flake
and is addressed in #1905.--no-sandbox into Stagehand's Chromium launch when sandbox is disabled (#1906)1 parent feec30d commit 041b92a
2 files changed
Lines changed: 32 additions & 0 deletions
File tree
- src/crawlee/browsers
- tests/unit/browsers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
91 | 100 | | |
92 | 101 | | |
93 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
67 | 90 | | |
68 | 91 | | |
69 | 92 | | |
| |||
0 commit comments