Spaces:
Build error
Build error
File size: 790 Bytes
057ddf0 f96374a 057ddf0 f96374a 057ddf0 f96374a 057ddf0 f96374a 057ddf0 f96374a 057ddf0 f96374a 057ddf0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
use chromiumoxide::browser::{Browser, BrowserConfig};
use chromiumoxide::page::Page;
use futures_util::StreamExt;
pub async fn init_browser() -> (Browser, Page) {
let (browser, mut handler) = Browser::launch(
BrowserConfig::builder()
.arg("--no-sandbox")
.arg("--disable-setuid-sandbox")
.arg("--headless")
.build()
.unwrap(),
)
.await
.unwrap();
// Critical: Keep the browser handler running in the background
tokio::spawn(async move {
while let Some(h) = handler.next().await {
if let Err(e) = h {
eprintln!("Browser handler error: {}", e);
}
}
});
let page = browser.new_page("about:blank").await.unwrap();
(browser, page)
} |