Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(browser): add support for the new headless mode in BrowserConfig #208

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,22 @@
}
}

#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
enum HeadlessMode {
/// The "headful" mode.
False,
/// The old headless mode.
#[default]
True,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be #[default]

/// The new headless mode. See also: https://developer.chrome.com/docs/chromium/new-headless
New,
}

#[derive(Debug, Clone)]
pub struct BrowserConfig {
/// Determines whether to run headless version of the browser. Defaults to
/// true.
headless: bool,
headless: HeadlessMode,
/// Determines whether to run the browser with a sandbox.
sandbox: bool,
/// Launch the browser with a specific window width and height.
Expand Down Expand Up @@ -619,7 +630,7 @@

#[derive(Debug, Clone)]
pub struct BrowserConfigBuilder {
headless: bool,
headless: HeadlessMode,
sandbox: bool,
window_size: Option<(u32, u32)>,
port: u16,
Expand Down Expand Up @@ -652,7 +663,7 @@
impl Default for BrowserConfigBuilder {
fn default() -> Self {
Self {
headless: true,
headless: HeadlessMode::True,
sandbox: true,
window_size: None,
port: 0,
Expand Down Expand Up @@ -686,7 +697,17 @@
}

pub fn with_head(mut self) -> Self {
self.headless = false;
self.headless = HeadlessMode::False;
self
}

pub fn new_headless_mode(mut self) -> Self {
self.headless = HeadlessMode::New;
self
}

pub fn headless_mode(mut self, HeadlessMode: mode) -> Self {

Check failure on line 709 in src/browser.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find type `mode` in this scope

Check failure on line 709 in src/browser.rs

View workflow job for this annotation

GitHub Actions / msrv

cannot find type `mode` in this scope

Check failure on line 709 in src/browser.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

cannot find type `mode` in this scope

Check failure on line 709 in src/browser.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot find type `mode` in this scope
self.headless = mode;

Check failure on line 710 in src/browser.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find value `mode` in this scope

Check failure on line 710 in src/browser.rs

View workflow job for this annotation

GitHub Actions / msrv

cannot find value `mode` in this scope

Check failure on line 710 in src/browser.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

cannot find value `mode` in this scope

Check failure on line 710 in src/browser.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot find value `mode` in this scope
self
}

Expand Down Expand Up @@ -889,8 +910,10 @@
cmd.args(["--no-sandbox", "--disable-setuid-sandbox"]);
}

if self.headless {
cmd.args(["--headless", "--hide-scrollbars", "--mute-audio"]);
match self.headless {
HeadlessMode::False => {}
HeadlessMode::True => cmd.args(["--headless", "--hide-scrollbars", "--mute-audio"]),

Check failure on line 915 in src/browser.rs

View workflow job for this annotation

GitHub Actions / Check

`match` arms have incompatible types

Check failure on line 915 in src/browser.rs

View workflow job for this annotation

GitHub Actions / msrv

`match` arms have incompatible types

Check failure on line 915 in src/browser.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest)

`match` arms have incompatible types

Check failure on line 915 in src/browser.rs

View workflow job for this annotation

GitHub Actions / Clippy

`match` arms have incompatible types
HeadlessMode::New => cmd.args(["--headless=new", "--hide-scrollbars", "--mute-audio"]),
}

if self.incognito {
Expand Down
Loading