Skip to content

Commit

Permalink
Add extra logging for failed browsershot attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Apr 1, 2022
1 parent 36e8661 commit 50eae92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Browsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,12 @@ public function save(string $targetPath)

$command = $this->createScreenshotCommand($targetPath);

$this->callBrowser($command);
$output = $this->callBrowser($command);

$this->cleanupTemporaryHtmlFile();

if (! file_exists($targetPath)) {
throw CouldNotTakeBrowsershot::chromeOutputEmpty($targetPath, $command);
throw CouldNotTakeBrowsershot::chromeOutputEmpty($targetPath, $output, $command);
}

if (! $this->imageManipulations->isEmpty()) {
Expand Down Expand Up @@ -797,7 +797,7 @@ protected function cleanupTemporaryOptionsFile()
}
}

protected function callBrowser(array $command)
protected function callBrowser(array $command): string
{
$fullCommand = $this->getFullCommand($command);

Expand Down
14 changes: 12 additions & 2 deletions src/Exceptions/CouldNotTakeBrowsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@

class CouldNotTakeBrowsershot extends Exception
{
public static function chromeOutputEmpty(string $screenShotPath, array $command = [])
public static function chromeOutputEmpty(string $screenShotPath, string $output, array $command = [])
{
$command = json_encode($command);

return new static("For some reason Chrome did not write a file at `{$screenShotPath}`. Command payload: {$command}");
$message = <<<CONSOLE
For some reason Chrome did not write a file at `{$screenShotPath}`.
Command
=======
{$command}
Output
======
{$output}
CONSOLE;

return new static($message);
}

public static function outputFileDidNotHaveAnExtension(string $path)
Expand Down

0 comments on commit 50eae92

Please sign in to comment.