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

Taking a Full Page screenshot using Symfony Panther? #587

Open
solkad opened this issue Feb 20, 2023 · 0 comments
Open

Taking a Full Page screenshot using Symfony Panther? #587

solkad opened this issue Feb 20, 2023 · 0 comments

Comments

@solkad
Copy link

solkad commented Feb 20, 2023

I was able to use Panther to take a full page screenshot using the following code, which uses document.documentElement:

<?php

require __DIR__.'/vendor/autoload.php';

use Symfony\Component\Panther\Client;
use Facebook\WebDriver\WebDriverDimension;

$client = Client::createChromeClient();
$client->request('GET', 'http://bot.sannysoft.com');

$width = $client->executeScript('return document.documentElement.scrollWidth');
$height = $client->executeScript('return document.documentElement.scrollHeight');

$size = new WebDriverDimension($width, $height);
$client->manage()->window()->setSize($size);
$client->takeScreenshot('screenshot.png');

However, I'm not sure this will always work. Is there a default way in Panther to take a full page screenshot? I found references online to using larger window dimensions, but not anything about an automatically sized screenshot.

In Chrome-PHP, it says, "You can also take a screenshot for the full-page layout (not only the viewport) using $page->getFullPageClip with attribute captureBeyondViewport = true":

$screenshot = $page->screenshot([
    'captureBeyondViewport' => true,
    'clip' => $page->getFullPageClip(),
    'format' => 'jpeg', // default to 'png' - possible values: 'png', 'jpeg',
]);

In PuPHPeteer, you can set fullPage to true:

$page->screenshot(['path' => 'example.png', 'fullPage'=> true]);

I don't know if there is any sort of built in way to take a full page screenshot like that in Panther or not. Or if you have to set the width and height manually.

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

No branches or pull requests

1 participant