2

如何在 ChromeOptions 中禁用图像加载?(PHP 库)

我尝试了以下但不确定语法是否正确

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

2 回答 2

2

留下以下更完整的示例以供将来参考:

这是有效的:

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

这也是有效的:

        $options = new ChromeOptions();

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

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

以下不起作用:

       $options = new ChromeOptions();

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

        $result = DesiredCapabilities::chrome();

        $result->setCapability(
            ChromeOptions::CAPABILITY_W3C,
            $options // Notice that ->toArray() is NOT used
        );
于 2020-10-03T20:50:34.387 回答
2

要禁用,请使用以下参数:--blink-settings=imagesEnabled=false

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

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

于 2019-11-01T09:52:52.560 回答