Skip to content

Commit d985a4f

Browse files
committed
Merge pull request #2 from Aerowalk/master
Added delay parameter on capture command
2 parents 378429c + 54dd8c1 commit d985a4f

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/JonnyW/PhantomJs/Client.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,17 @@ public function open(RequestInterface $request, ResponseInterface $response, $de
136136
* @param string $file
137137
* @return \JonnyW\PhantomJs\Message\ResponseInterface
138138
*/
139-
public function capture(RequestInterface $request, ResponseInterface $response, $file)
139+
public function capture(RequestInterface $request, ResponseInterface $response, $file, $delay = 0)
140140
{
141141
if (!is_writable(dirname($file))) {
142142
throw new NotWriteableException(sprintf('Path is not writeable by PhantomJs: %s', $file));
143143
}
144144

145-
$cmd = sprintf($this->captureCmd, $file);
145+
if ($delay) {
146+
$cmd = sprintf($this->captureCmdWithDelay, $file, $delay);
147+
} else {
148+
$cmd = sprintf($this->captureCmd, $file);
149+
}
146150

147151
return $this->request($request, $response, $cmd);
148152
}
@@ -352,6 +356,27 @@ protected function parse($data)
352356
phantom.exit();
353357
EOF;
354358

359+
/**
360+
* PhantomJs screen capture
361+
* command template
362+
* delay
363+
*
364+
* @var string
365+
*/
366+
protected $captureCmdWithDelay = <<<EOF
367+
368+
window.setTimeout(function () {
369+
page.render('%1\$s');
370+
371+
response.content = page.evaluate(function () {
372+
return document.getElementsByTagName('html')[0].innerHTML
373+
});
374+
375+
console.log(JSON.stringify(response, undefined, 4));
376+
phantom.exit();
377+
}, %2\$s);
378+
EOF;
379+
355380
/**
356381
* PhantomJs page open
357382
* command template

0 commit comments

Comments
 (0)