Skip to content

Commit 20d577b

Browse files
committed
move caps to webdriver
Signed-off-by: Andrei Gherghescu <[email protected]>
1 parent ac74cc9 commit 20d577b

File tree

2 files changed

+70
-67
lines changed

2 files changed

+70
-67
lines changed

plotly_static/src/lib.rs

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -278,71 +278,6 @@ use webdriver::WebDriver;
278278

279279
use crate::template::{image_export_js_script, pdf_export_js_script};
280280

281-
#[cfg(all(feature = "chromedriver", not(target_os = "windows")))]
282-
fn chrome_default_caps() -> Vec<&'static str> {
283-
vec![
284-
"--headless",
285-
"--no-sandbox",
286-
"--disable-gpu-sandbox",
287-
"--disable-dev-shm-usage",
288-
"--disable-extensions",
289-
"--disable-background-networking",
290-
"--disable-sync",
291-
"--disable-translate",
292-
"--disable-background-timer-throttling",
293-
"--disable-renderer-backgrounding",
294-
"--disable-features=VizDisplayCompositor",
295-
"--memory-pressure-off",
296-
// macOS-specific flags from choreographer
297-
"--enable-unsafe-swiftshader",
298-
"--use-mock-keychain",
299-
"--password-store=basic",
300-
"--disable-web-security",
301-
"--disable-breakpad",
302-
"--no-first-run",
303-
"--no-default-browser-check",
304-
// Additional flags for better PDF generation support
305-
"--disable-backgrounding-occluded-windows",
306-
"--disable-ipc-flooding-protection",
307-
"--enable-logging",
308-
"--v=1",
309-
]
310-
}
311-
312-
#[cfg(all(feature = "chromedriver", target_os = "windows"))]
313-
fn chrome_default_caps() -> Vec<&'static str> {
314-
vec![
315-
"--headless=new",
316-
"--no-sandbox",
317-
"--disable-dev-shm-usage",
318-
"--disable-breakpad",
319-
"--no-first-run",
320-
"--no-default-browser-check",
321-
// Stability flags to prevent renderer crashes
322-
"--disable-background-networking",
323-
"--disable-sync",
324-
"--disable-translate",
325-
"--disable-background-timer-throttling",
326-
"--disable-renderer-backgrounding",
327-
"--disable-backgrounding-occluded-windows",
328-
"--disable-ipc-flooding-protection",
329-
"--disable-extensions",
330-
// Minimal flags for Windows headless operation without disabling GPU
331-
"--hide-scrollbars",
332-
"--mute-audio",
333-
"--use-angle=swiftshader",
334-
"--disable-software-rasterizer",
335-
]
336-
}
337-
338-
#[cfg(feature = "geckodriver")]
339-
fn firefox_default_caps() -> Vec<&'static str> {
340-
vec![
341-
"-headless", // Essential for headless operation (single dash for Firefox)
342-
"--no-remote", // Prevents connecting to existing Firefox instances
343-
]
344-
}
345-
346281
mod template;
347282
mod webdriver;
348283

@@ -506,14 +441,14 @@ impl Default for StaticExporterBuilder {
506441
webdriver_browser_caps: {
507442
#[cfg(feature = "chromedriver")]
508443
{
509-
chrome_default_caps()
444+
crate::webdriver::chrome_default_caps()
510445
.into_iter()
511446
.map(|s| s.to_string())
512447
.collect()
513448
}
514449
#[cfg(feature = "geckodriver")]
515450
{
516-
firefox_default_caps()
451+
crate::webdriver::firefox_default_caps()
517452
.into_iter()
518453
.map(|s| s.to_string())
519454
.collect()

plotly_static/src/webdriver.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,74 @@ pub(crate) const WEBDRIVER_PORT: u32 = 4444;
3434
/// Default WebDriver URL
3535
pub(crate) const WEBDRIVER_URL: &str = "http://localhost";
3636

37+
#[cfg(all(feature = "chromedriver", not(target_os = "windows")))]
38+
pub(crate) fn chrome_default_caps() -> Vec<&'static str> {
39+
vec![
40+
"--headless",
41+
"--no-sandbox",
42+
"--disable-gpu-sandbox",
43+
"--disable-dev-shm-usage",
44+
"--disable-extensions",
45+
"--disable-background-networking",
46+
"--disable-sync",
47+
"--disable-translate",
48+
"--disable-background-timer-throttling",
49+
"--disable-renderer-backgrounding",
50+
"--disable-features=VizDisplayCompositor",
51+
"--memory-pressure-off",
52+
// macOS-specific flags from choreographer
53+
"--enable-unsafe-swiftshader",
54+
"--use-mock-keychain",
55+
"--password-store=basic",
56+
"--disable-web-security",
57+
"--allow-file-access-from-files",
58+
"--disable-breakpad",
59+
"--no-first-run",
60+
"--no-default-browser-check",
61+
// Additional flags for better PDF generation support
62+
"--disable-backgrounding-occluded-windows",
63+
"--disable-ipc-flooding-protection",
64+
"--enable-logging",
65+
"--v=1",
66+
]
67+
}
68+
69+
#[cfg(all(feature = "chromedriver", target_os = "windows"))]
70+
pub(crate) fn chrome_default_caps() -> Vec<&'static str> {
71+
vec![
72+
"--headless=new",
73+
"--no-sandbox",
74+
"--disable-dev-shm-usage",
75+
"--disable-breakpad",
76+
"--no-first-run",
77+
"--no-default-browser-check",
78+
// Stability flags to prevent renderer crashes
79+
"--disable-background-networking",
80+
"--disable-sync",
81+
"--disable-translate",
82+
"--disable-background-timer-throttling",
83+
"--disable-renderer-backgrounding",
84+
"--disable-backgrounding-occluded-windows",
85+
"--disable-ipc-flooding-protection",
86+
"--disable-extensions",
87+
"--disable-web-security",
88+
"--allow-file-access-from-files",
89+
// Minimal flags for Windows headless operation without disabling GPU
90+
"--hide-scrollbars",
91+
"--mute-audio",
92+
"--use-angle=swiftshader",
93+
"--disable-software-rasterizer",
94+
]
95+
}
96+
97+
#[cfg(feature = "geckodriver")]
98+
pub(crate) fn firefox_default_caps() -> Vec<&'static str> {
99+
vec![
100+
"-headless", // Essential for headless operation (single dash for Firefox)
101+
"--no-remote", // Prevents connecting to existing Firefox instances
102+
]
103+
}
104+
37105
/// Internal WebDriver state
38106
#[derive(Debug)]
39107
struct WdInner {

0 commit comments

Comments
 (0)