Skip to content

Commit

Permalink
manual PATH scanner instead of command
Browse files Browse the repository at this point in the history
command is not always available in shell_exec()
see chrome-php#613 for details
  • Loading branch information
divinity76 committed Mar 19, 2024
1 parent dc463f0 commit 9ef7a46
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/AutoDiscover.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,24 @@ public function guessChromeBinaryPath(): string
return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
case 'Windows':
return self::getFromRegistry() ?? '%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe';
default:
return \rtrim(\explode("\n", (string) self::shellExec('command -v google-chrome chromium-browser chrome chromium'), 2)[0]) ?: 'chrome';
default: {
$valid_names = array(
'google-chrome',
'chromium-browser',
'chrome',
'chromium',
);
foreach (\explode(\PATH_SEPARATOR, \getenv('PATH')) as $dir) {
foreach ($valid_names as $name) {
$file = $dir . \DIRECTORY_SEPARATOR . $name;
if (\is_file($file) && \is_executable($file)) {
return $file;
}
}
}
return 'chrome'; // ... very unlikely to actually work, but this retains the original behavior..
throw new \RuntimeException('Could not find chrome binary'); // this makes more sense tbh
}
}
}

Expand Down

0 comments on commit 9ef7a46

Please sign in to comment.