screenshot() calls activate() which steals window focus on every capture
## Problem
The `screenshot()` method in `handler/page.rs` unconditionally calls `self.activate()` before capturing:
https://github.com/mattsse/chromiumoxide/blob/main/src/handler/page.rs#L387
```rust
pub async fn screenshot(&self, params: impl Into<ScreenshotParams>) -> Result<Vec<u8>> {
self.activate().await?; // sends ActivateTargetParams
// ...
}
```
This sends `Target.activateTarget` via CDP, which brings the browser window to the OS foreground on every screenshot. For automation agents that take screenshots every few seconds (e.g. after each action), this makes the browser repeatedly steal focus from whatever the user is working on.
## Expected behavior
`CaptureScreenshot` works fine via CDP without activating the target first — the screenshot is captured from the page's render tree regardless of window focus. The `activate()` call is unnecessary for single-tab use cases and harmful for headful automation where the user wants to multitask.
## Suggested fix
Either:
1. Remove the `activate()` call from `screenshot()` entirely, or
2. Make it opt-in via a parameter on `ScreenshotParams` (e.g. `activate_before_capture`)
## Workaround
Calling `page.execute(CaptureScreenshotParams { format: Some(Png), .. })` directly bypasses the issue.
## Environment
- chromiumoxide 0.8.0
- macOS (though the issue applies to any OS where `Target.activateTarget` brings the window to front)
0 条评论