feat: add fullpage and maxheight parameters for enhanced screenshot options
All checks were successful
Build Container / docker (push) Successful in 4m13s
All checks were successful
Build Container / docker (push) Successful in 4m13s
This commit is contained in:
@@ -63,6 +63,18 @@ switch ($url[0]) {
|
||||
|
||||
$js = $_REQUEST['js'] == 'false' ? false : true;
|
||||
|
||||
$fullpage = isset($_REQUEST['fullpage']) && $_REQUEST['fullpage'] === 'true';
|
||||
$maxheight = 15000;
|
||||
if (isset($_REQUEST['maxheight'])) {
|
||||
$mh = intval($_REQUEST['maxheight']);
|
||||
if ($mh < 1 || $mh > 30000) {
|
||||
header('HTTP/1.0 400 Bad Request');
|
||||
echo 'maxheight must be between 1 and 30000';
|
||||
exit;
|
||||
}
|
||||
$maxheight = $mh;
|
||||
}
|
||||
|
||||
if (defined('BLOCK_PRIVATE_IPS') && BLOCK_PRIVATE_IPS) {
|
||||
$host = parse_url($target, PHP_URL_HOST);
|
||||
if (filter_var($host, FILTER_VALIDATE_IP)) {
|
||||
@@ -98,9 +110,19 @@ switch ($url[0]) {
|
||||
$driver = RemoteWebDriver::create($serverUrl, $capabilities, 30000, 60000);
|
||||
$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($vpParts[0], $vpParts[1]));
|
||||
$driver->get($target);
|
||||
$driver->executeScript('document.body.style.overflow = "hidden";');
|
||||
|
||||
addToLog($ip . ' Requested ' . $target . ' viewport=' . $viewport . ' js=' . ($js ? 'enabled' : 'disabled'));
|
||||
if ($fullpage) {
|
||||
$fullH = (int)$driver->executeScript('return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)');
|
||||
$cappedH = min($fullH, $maxheight);
|
||||
if ($cappedH < $fullH) {
|
||||
addToLog($ip . ' Full-page height capped at ' . $maxheight . 'px (actual: ' . $fullH . 'px) for ' . $target);
|
||||
}
|
||||
$driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($vpParts[0], $cappedH));
|
||||
} else {
|
||||
$driver->executeScript('document.body.style.overflow = "hidden";');
|
||||
}
|
||||
|
||||
addToLog($ip . ' Requested ' . $target . ' viewport=' . $viewport . ' js=' . ($js ? 'enabled' : 'disabled') . ($fullpage ? ' fullpage=true' : ''));
|
||||
|
||||
$screenshot = $driver->takeScreenshot();
|
||||
header('Content-Type: image/png');
|
||||
|
||||
Reference in New Issue
Block a user