Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HeadlessChromium saving first image as a new directory folder instead of an image.. #32

Closed
Cmaxster opened this issue Aug 13, 2018 · 2 comments
Labels

Comments

@Cmaxster
Copy link

Cmaxster commented Aug 13, 2018

The first time I run this via JavaScript POST, HeadlessChromium saves out a new directory folder instead of an image (with the image_name.jpg as the folder name). But when my JavaScript continues to call the script, it saves out an image on each consecutive call..

What would cause HeadlessChromium to save the first image as a directory, but all of the others as JPGs?

My Javascript seems fine.. it's sending the same type of data each time, the script doesn't change on each consecutive call, yet I keep getting a different result on the first call only..

Anyone know what's up here?

<?php
    require 'vendor/autoload.php';
    use HeadlessChromium\BrowserFactory;


    $delay = 15; // 15 seconds

    $bannerName = $_POST['bannerName'];
    $htmlFile = $_POST['htmlFile'];
    $sessionId = $_POST['sessionId'];



    // headless-chromium-php
    $browserFactory = new BrowserFactory('/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome');
    $browser = $browserFactory->createBrowser([
        'headless'        => true,         // disable headless mode
        'connectionDelay' => 0,           // add 0.8 second of delay between each instruction sent to chrome,
        'debugLogger'     => 'php://stdout',  // will enable verbose mode
        'windowSize' => [900, 650],
        'startupTimeout' => 50
    ]);
    $page = $browser->createPage();
    $page->navigate('http://localhost:8888/phpBackend/'.$htmlFile)->waitForNavigation('networkIdle', 10000);  
    $pageTitle = $bannerName; //$page->evaluate('document.title')->getReturnValue();
    sleep(15);
    $screenshot = $page->screenshot([
        'format'  => 'jpeg',  // default to 'png' - possible values: 'png', 'jpeg',
        'quality' => 80       // only if format is 'jpeg' - default 100 
    ])->saveToFile('./backups/'.$sessionId."/".$bannerName.".jpg");
    $browser->close();


    $responsed = array("bannerName" => $bannerName, "htmlFile" => $htmlFile);

    echo json_encode($responsed);

?>

Error logs:


[13-Aug-2018 23:24:09 Europe/Berlin] PHP Warning:  fopen(./backups/C30465E8-748F-70B0-B570-79D9E867FB3B/en_300x250_banner.jpg): failed to open stream: Is a directory in /Applications/MAMP/htdocs/phpBackend/vendor/chrome-php/chrome/src/PageUtils/PageScreenshot.php on line 96
[13-Aug-2018 23:24:09 Europe/Berlin] PHP Warning:  stream_filter_append() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/phpBackend/vendor/chrome-php/chrome/src/PageUtils/PageScreenshot.php on line 97
[13-Aug-2018 23:24:09 Europe/Berlin] PHP Warning:  fwrite() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/phpBackend/vendor/chrome-php/chrome/src/PageUtils/PageScreenshot.php on line 98
[13-Aug-2018 23:24:09 Europe/Berlin] PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in /Applications/MAMP/htdocs/phpBackend/vendor/chrome-php/chrome/src/PageUtils/PageScreenshot.php on line 99
@gsouf
Copy link
Member

gsouf commented Aug 28, 2018

Good catch thanks.

That's coming with the next release in a few minutes

@gsouf gsouf added the bug label Aug 28, 2018
@gsouf gsouf closed this as completed in 7128a57 Aug 28, 2018
@Cmaxster
Copy link
Author

Ok thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants