Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Webdriver Selenium Firefox headless mode

Tags:

haskell

I enjoy using the wonderful webdriver package. But one thing that's a bit odd is that the Firefox browser type doesn't support commandline options. Can anyone help how I can run firefox headless mode with commandline options? I'm guessing I could use firefox profile but after much googling I couldn't find headless mode linked to firefox profile.

data Browser = Firefox { -- |The firefox profile to use. If Nothing,
                         -- a default temporary profile is automatically created
                         -- and used.
                         ffProfile :: Maybe (PreparedProfile Firefox)
                         -- |Firefox logging preference
                       , ffLogPref :: LogLevel
                         -- |Server-side path to Firefox binary. If Nothing,
                         -- use a sensible system-based default.
                       , ffBinary :: Maybe FilePath
                         -- |Available after Firefox 52, and required only for Firefox
                         -- geckodriver. Indicates whether untrusted and self-signed TLS
                         -- certificates are implicitly trusted on navigation for the
                         -- duration of the session.
                       , ffAcceptInsecureCerts :: Maybe Bool
                       }
             | Chrome { -- |Version of the Chrome Webdriver server server to use
                        --
                        -- for more information on chromedriver see
                        -- <https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver>
                        chromeDriverVersion :: Maybe String
                        -- |Server-side path to Chrome binary. If Nothing,
                        -- use a sensible system-based default.
                      , chromeBinary :: Maybe FilePath
                        -- |A list of command-line options to pass to the
                        -- Chrome binary.
                      , chromeOptions :: [String]
                        -- |A list of extensions to use.
                      , chromeExtensions :: [ChromeExtension]
                        -- | Experimental options not yet exposed through a standard API.
                      , chromeExperimentalOptions :: Object
                      }
like image 293
McBear Holden Avatar asked Dec 20 '25 19:12

McBear Holden


1 Answers

For now, there's no specific switch built into the Haskell library, so you'll have to use the additionalCaps field inside the wdCapabilities field of your WDConfig, rather than the browser field, and include an args array inside a moz:firefoxOptions aeson object like this:

firefoxConfig ∷ WDConfig
firefoxConfig = defaultConfig {
    wdCapabilities = defaultCaps {
        additionalCaps = [
            ("moz:firefoxOptions", object [
                ("args", Array (fromList [String "--headless"]))
            ])
        ]
    }
}

Anything else undocumented in Haskell that you wish to pass to Firefox will also go there.

This is explained in Mozilla's documentation.

like image 187
Dan Dart Avatar answered Dec 23 '25 12:12

Dan Dart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!