Use Case
I'm building a performance testing tool for a WASM application that runs its core logic in a Web Worker. The Worker uses WebCodecs VideoDecoder for H.264 decode and exposes metrics via a JS API. I need to:
- Detect Worker targets when they spawn
- Evaluate JavaScript in the Worker context to read performance metrics
- Optionally listen for console messages from Workers
This is a common pattern for any application using Web Workers: PWAs, video players, WASM-heavy apps, etc.
Current Behavior
chromiumoxide currently cannot interact with Worker targets:
- Service workers are auto-detached:
on_event() in handler/target.rs immediately detaches "service_worker" targets on attachment
- Non-page targets skip initialization:
poll() returns None for !self.is_page(), so Workers never reach Initialized state
- No public API for Worker sessions:
Browser::execute() sends with session_id: None (browser-level only)
The TargetType enum already has ServiceWorker, SharedWorker, and BackgroundPage variants with is_*() methods, suggesting this was anticipated but not implemented.
How Puppeteer/Playwright Handle This
Both tools implement Worker evaluation using standard CDP:
Target.setAutoAttach { autoAttach: true, flatten: true, waitForDebuggerOnStart: false }
-> attachedToTarget event (targetInfo.type == "worker")
-> sessionId for the Worker
-> Runtime.evaluate on that sessionId
Chrome CDP fully supports this. The limitation is purely in chromiumoxide's abstraction layer.
Proposed Changes
- Remove auto-detach for service workers in
on_event(), or make it configurable
- Generalize
poll() initialization: allow non-page targets to reach a basic Initialized state (they don't need frame/network/emulation init, just Runtime)
- Expose Worker session API, something like:
// Get Worker targets
let workers = page.workers().await?;
// Evaluate JS in a Worker
let result = worker.evaluate("self.performance_stats()").await?;
The internal transport already supports session routing via CommandMessage::with_session(). The session_id flows correctly through conn.rs. The change is in the public API surface and initialization pipeline.
Alternatives Considered
- MessageChannel bridge: Worker posts to main page, evaluate on page context. Works but adds latency and indirection.
- Raw WebSocket to CDP: bypass chromiumoxide entirely for Worker commands. Works but defeats the purpose of using the library.
- Fork: would rather contribute upstream if there's interest.
Environment
- chromiumoxide v0.9.1
- Chrome 133+
- Using Workers for WASM (wasm-bindgen) with WebCodecs VideoDecoder
Happy to submit a PR if there's interest in this feature.
Use Case
I'm building a performance testing tool for a WASM application that runs its core logic in a Web Worker. The Worker uses WebCodecs VideoDecoder for H.264 decode and exposes metrics via a JS API. I need to:
This is a common pattern for any application using Web Workers: PWAs, video players, WASM-heavy apps, etc.
Current Behavior
chromiumoxide currently cannot interact with Worker targets:
on_event()inhandler/target.rsimmediately detaches"service_worker"targets on attachmentpoll()returnsNonefor!self.is_page(), so Workers never reachInitializedstateBrowser::execute()sends withsession_id: None(browser-level only)The
TargetTypeenum already hasServiceWorker,SharedWorker, andBackgroundPagevariants withis_*()methods, suggesting this was anticipated but not implemented.How Puppeteer/Playwright Handle This
Both tools implement Worker evaluation using standard CDP:
Chrome CDP fully supports this. The limitation is purely in chromiumoxide's abstraction layer.
Proposed Changes
on_event(), or make it configurablepoll()initialization: allow non-page targets to reach a basicInitializedstate (they don't need frame/network/emulation init, just Runtime)The internal transport already supports session routing via
CommandMessage::with_session(). Thesession_idflows correctly throughconn.rs. The change is in the public API surface and initialization pipeline.Alternatives Considered
Environment
Happy to submit a PR if there's interest in this feature.