Skip to content

Instantly share code, notes, and snippets.

@acro5piano
Created February 11, 2026 07:49
Show Gist options
  • Select an option

  • Save acro5piano/633d30fed49817778b07ed261f9bff5f to your computer and use it in GitHub Desktop.

Select an option

Save acro5piano/633d30fed49817778b07ed261f9bff5f to your computer and use it in GitHub Desktop.
cdp test using chromiumoxide - by attaching existing headed chrome instance (not launching a new one)

Run chromium instance in the terminal beforehand:

chromium --remote-debugging-port=9222 
[package]
name = "cdp_test"
version = "0.1.0"
edition = "2024"
[dependencies]
anyhow = "1.0.101"
chromiumoxide = { version = "0.8", features = ["tokio-runtime"], default-features = false }
env_logger = "0.11.8"
futures = "0.3"
log = "0.4.29"
tokio = { version = "1.49.0", features = ["full"] }
use chromiumoxide::Browser;
use futures::StreamExt;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();
let (browser, mut handler) = Browser::connect("http://127.0.0.1:9222").await?;
let handle = tokio::spawn(async move {
while let Some(event) = handler.next().await {
if event.is_err() {
break;
}
}
});
// This delay important; otherwise result in "No pages found"
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
let pages = browser.pages().await?;
let page = pages
.get(0)
.ok_or_else(|| anyhow::anyhow!("No pages found"))?;
page.reload().await?;
page.goto("https://example.com").await?;
handle.abort();
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment