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

Make Fetcher public #467

Open
Subhra264 opened this issue Mar 4, 2024 · 0 comments
Open

Make Fetcher public #467

Subhra264 opened this issue Mar 4, 2024 · 0 comments

Comments

@Subhra264
Copy link

The fetch method of Fetcher looks for existing chrome installations, otherwise installs one which is cool. But if I am not missing anything, there is no public function that makes the fetch function available for use. The fetch function is called intenally only when Browser::new() is called.

So, suppose we have a REST Rust server and there is an API to generate some report. The API request handler internally uses headless chrome and launches browser for each request. Then the first request will wait until Browser::new installs chrome.

If Fetcher is public, then I don't need to use Browser::new() for the installation. Instead, I can pass env configurations to the server initializer function and install chrome while setting up the server only -

/// A global static launchoptions settings
pub static CHROME_LAUNCHER_OPTIONS: Lazy<LaunchOptions<'_>> = Lazy::new(|| {
        let mut options = LaunchOptions::default_builder();
        options
            .window_size(Some((
                CONFIG.chrome.chrome_window_width,
                CONFIG.chrome.chrome_window_height,
            )))
            .enable_logging(CONFIG.chrome.chrome_enable_logging)
            .idle_browser_timeout(Duration::from_secs(
                CONFIG.chrome.chrome_idle_timeout.into(),
            ));

        if !CONFIG.chrome.chrome_path.is_empty() {
            options.path(Some(CONFIG.chrome.chrome_path.clone().into()));
        }

        let mut options = options.build().unwrap();
        // Install chrome executable now and not while creating browser instance
       if options.path.is_none() {
            let fetch = Fetcher::new(options.fetcher_options.clone());
            options.path = Some(fetch.fetch().unwrap());
        }
        options
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant