From 6a95cdad9d0eb6fd9d30426df966c225080e5d3d Mon Sep 17 00:00:00 2001 From: freek Date: Mon, 20 Nov 2017 23:11:32 +0100 Subject: [PATCH] refactor delayed screenshots --- CHANGELOG.md | 4 +++- README.md | 4 ++-- src/Browsershot.php | 11 ++--------- tests/BrowsershotTest.php | 6 +++--- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb245926..72d58250 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to `Browsershot` will be documented in this file +### 3.12.0 - 2017-11-20 + +- add `setDelay` ### 3.11.1 - 2017-11-18 @@ -12,7 +15,6 @@ All notable changes to `Browsershot` will be documented in this file - add `setOption` - refactor internals - ### 3.10.0 - 2017-11-13 - add `setProxyServer` diff --git a/README.md b/README.md index 293d0698..f9b426ef 100644 --- a/README.md +++ b/README.md @@ -206,11 +206,11 @@ Browsershot::url('https://example.com') ``` #### Delayed screenshots -You can delay execution of the screenshot by a specified amount of time by using `setDelay()`. This is useful if you need to wait for completion of javascript or if you are attempting to capture lazy-loaded resources. Delay time is measured in milliseconds. +You can delay the taking of screenshot by `setDelay()`. This is useful if you need to wait for completion of javascript or if you are attempting to capture lazy-loaded resources. ```php Browsershot::url('https://example.com') - ->setDelay(5000) + ->setDelay($delayInMilliseconds) ->save($pathToImage); ``` diff --git a/src/Browsershot.php b/src/Browsershot.php index 373b9a68..c58b23a1 100644 --- a/src/Browsershot.php +++ b/src/Browsershot.php @@ -23,7 +23,6 @@ class Browsershot protected $temporaryHtmlDirectory; protected $timeout = 60; protected $url = ''; - protected $delay = 0; protected $additionalOptions = []; /** @var \Spatie\Image\Manipulations */ @@ -237,11 +236,9 @@ public function windowSize(int $width, int $height) ->setOption('viewport.height', $height); } - public function setDelay(int $delay) + public function setDelay(int $delayInMilliseconds) { - $this->delay = $delay; - - return $this; + return $this->setOption('delay', $delayInMilliseconds); } public function setOption($key, $value) @@ -329,10 +326,6 @@ public function createScreenshotCommand(string $targetPath): array $command['options']['omitBackground'] = true; } - if ($this->delay > 0) { - $command['options']['delay'] = $this->delay; - } - return $command; } diff --git a/tests/BrowsershotTest.php b/tests/BrowsershotTest.php index ae3ea5b8..853a81ca 100644 --- a/tests/BrowsershotTest.php +++ b/tests/BrowsershotTest.php @@ -434,12 +434,12 @@ public function it_can_set_arbitrary_options() public function it_can_add_a_delay_before_taking_a_screenshot() { $targetPath = __DIR__.'/temp/testScreenshot.png'; - $delay = 5000; - $start = round(microtime(true) * 1000); + $delay = 2000; + $start = round(microtime(true) * 2000); Browsershot::url('https://example.com') ->setDelay($delay) ->save($targetPath); - $end = round(microtime(true) * 1000); + $end = round(microtime(true) * 2000); $this->assertGreaterThanOrEqual($delay, $end - $start); }