You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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?
Error logs:
The text was updated successfully, but these errors were encountered: