Search code examples
rustpuppeteermicrosoft-edgegoogle-chrome-headless

When I start Microsoft Edge in headless mode with rust-headless-chrome, an unknown window appears


I want to automate Microsoft Edge with rust-headless-chrome without opening any windows.

I started Edge in headless mode with the following Rust code:

use headless_chrome::browser::{Browser, LaunchOptions};
use std::ffi::OsStr;
use std::path::PathBuf;
use std::{thread, time::Duration};

fn main() {
    let _browser = Browser::new(LaunchOptions {
        headless: true,
        path: Some(PathBuf::from(r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe")),
        args: vec![OsStr::new("--profile-directory=Default")],
        ..Default::default()
    }).unwrap();
    thread::sleep(Duration::from_secs(5));
}

Then the following unknown window appeared: enter image description here

I tried adding the following arguments, which seemed promising to improve the problem, but the results did not change.

  • --headless
  • --silent-launch
  • --disable-logging
fn main() {
    let _browser = Browser::new(LaunchOptions {
        headless: true,
        path: Some(PathBuf::from(r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe")),
        args: vec![
            OsStr::new("--profile-directory=Default"),
            OsStr::new("--headless"),
            OsStr::new("--silent-launch"),
            OsStr::new("--disable-logging")],
        ..Default::default()
    }).unwrap();
    thread::sleep(Duration::from_secs(5));
}

My environment is as follows:

  • OS: Windows 10 Pro 22H2 64-bit
  • Rust toolchain: nightly-x86_64-pc-windows-gnu
  • rustc: 1.75.0-nightly (1c05d50c8 2023-10-21)
  • headless_chrome (rust-headless-chrome): 1.0.5
  • Microsoft Edge: 118.0.2088.61 (Official build) (64-bit)

Is it possible to run Edge with rust-headless-chrome automatically without opening any windows?


Solution

  • I solved the problem by updating the crate from 1.0.5 to 1.0.6 released on October 23, 2023.

    Thank you for your help and suggestions. I will mark this question as resolved.

    It seems that there was a change in the update to 1.0.6 that prevents the pop-up screen from appearing when launching the browser.