简体   繁体   中英

php HeadlessChromium\BrowserFactory not found in file.php

<?php
use HeadlessChromium\BrowserFactory;

$browserFactory = new BrowserFactory();

?>

I've installed chrome-php/chrome with composer and hovering my mouse over the class will give me the details but when I try to run the code I get the error:

PHP Fatal error:  Uncaught Error: Class 'HeadlessChromium\BrowserFactory' not found in file.php

Is there something I'm missing in the initial set up? Not sure why it isn't working. I'm using visual studio code and the bug appears in the debug console tab instead of the problems tab. I'm not getting any issues in the problems tab. Any idea why that is the case?

When using composer you need to include the autoloader on top of the script.

<?php
require __DIR__ . '/vendor/autoload.php';

use HeadlessChromium\BrowserFactory;

$browserFactory = new BrowserFactory();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM