2

How do you disable image loading in ChromeOptions? (PHP library)

I tried the following but not sure if syntax is correct

$options = new ChromeOptions();

// disable images
$options->addArguments(array(
   "service_args=['--load-images=no']"
));

$caps = DesiredCapabilities::chrome();
$caps->setCapability(ChromeOptions::CAPABILITY, $options);

$driver = RemoteWebDriver::create($host, $caps);
Robert Sinclair
  • 4,550
  • 2
  • 44
  • 46

2 Answers2

2

To disable, use the argument: --blink-settings=imagesEnabled=false

$options->addArguments(array(
    '--blink-settings=imagesEnabled=false'
));

https://github.com/facebook/php-webdriver/issues/641#issuecomment-512255496

Senror Gui
  • 80
  • 9
2

Leaving following fuller examples for future reference:

This is what works:

        $capabilities = DesiredCapabilities::chrome();
        $capabilities->setCapability('acceptInsecureCerts', true);
        $capabilities->setCapability(ChromeOptions::CAPABILITY_W3C, [
            'args' => [
                '--blink-settings=imagesEnabled=false',
            ]
        ]);

This is what also works:

        $options = new ChromeOptions();

        $options->addArguments(
            [
                '--blink-settings=imagesEnabled=false',
            ]
        );

        $result = DesiredCapabilities::chrome();
        
        $result->setCapability(
            ChromeOptions::CAPABILITY_W3C,
            $options->toArray() // Notice that ->toArray() is used
        );

The following does NOT work:

       $options = new ChromeOptions();

        $options->addArguments(
            [
                '--blink-settings=imagesEnabled=false',
            ]
        );

        $result = DesiredCapabilities::chrome();

        $result->setCapability(
            ChromeOptions::CAPABILITY_W3C,
            $options // Notice that ->toArray() is NOT used
        );
Boris D. Teoharov
  • 2,319
  • 4
  • 30
  • 49