Robert Sinclair
Robert Sinclair

Reputation: 5446

Disable image loading with PHP Selenium

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);

Upvotes: 2

Views: 798

Answers (2)

Boris D. Teoharov
Boris D. Teoharov

Reputation: 2388

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
        );

Upvotes: 2

Senror Gui
Senror Gui

Reputation: 90

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

Upvotes: 2

Related Questions