Skip to content

Commit

Permalink
Merge pull request #46 from stefanzweifel/feature/set-user-agent
Browse files Browse the repository at this point in the history
Use a new, simple user-agent
  • Loading branch information
stefanzweifel committed Feb 22, 2016
2 parents 386000a + f3d699b commit ca9eba4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .env.travis
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ SCREEENLY_STORAGE_PATH=images/generated/
SCREEENLY_PATH_TO_PHANTOMJS=/vendor/bin/phantomjs

RAVEN_DSN=secret
RAVEN_LEVEL=debug
RAVEN_LEVEL=none

SCHEDULER_PING_URL=secret
19 changes: 19 additions & 0 deletions app/Core/Client/PhantomJsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Screeenly\Core\Client;

use JonnyW\PhantomJs\Client;
use JonnyW\PhantomJs\DependencyInjection\ServiceContainer;

class PhantomJsClient extends AbstractClient implements ClientInterface
{
Expand All @@ -21,6 +22,9 @@ class PhantomJsClient extends AbstractClient implements ClientInterface
public function boot()
{
$client = Client::getInstance();

$client->getProcedureLoader()->addLoader($this->loadProcedurePartials());

$client->getEngine()->setPath(base_path().config('screeenly.core.path_to_phantomjs'));
$client->getEngine()->addOption('--load-images=true');
$client->getEngine()->addOption('--ignore-ssl-errors=true');
Expand Down Expand Up @@ -53,6 +57,21 @@ public function capture($url, $key = null)
return $this->screenshot;
}

/**
* Load our custom PhantomJS Procedures
* Let's us directly manipulate the PhantomJS Instance.
*
* @see http://jonnnnyw.github.io/php-phantomjs/4.0/custom-scripts/
* @return JonnyW\PhantomJs\Procedure\ProcedureLoader
*/
public function loadProcedurePartials()
{
$location = app_path('Core/Procedures/');
$serviceContainer = ServiceContainer::getInstance();

return $serviceContainer->get('procedure_loader_factory')->createProcedureLoader($location);
}

/**
* Contains the acutal logic on how to capture a Screenshot with
* PhantomJS Headless Browser.
Expand Down
4 changes: 4 additions & 0 deletions app/Core/Procedures/page_settings.partial
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

page.settings.resourceTimeout = {{ input.getTimeout() }};

page.settings.userAgent = 'screeenly-bot';
19 changes: 19 additions & 0 deletions app/Screenshot/PhantomJsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Screeenly\Screenshot;

use JonnyW\PhantomJs\Client;
use JonnyW\PhantomJs\DependencyInjection\ServiceContainer;

class PhantomJsClient implements ClientInterface
{
Expand All @@ -16,6 +17,9 @@ public function __construct()
public function build()
{
$client = Client::getInstance();

$client->getProcedureLoader()->addLoader($this->loadProcedurePartials());

$client->getEngine()->setPath(base_path().config('screeenly.core.path_to_phantomjs'));
$client->getEngine()->addOption('--load-images=true');
$client->getEngine()->addOption('--ignore-ssl-errors=true');
Expand Down Expand Up @@ -44,4 +48,19 @@ public function capture(Screenshot $screenshot)
$response = $this->client->getMessageFactory()->createResponse();
$this->client->send($request, $response);
}

/**
* Load our custom PhantomJS Procedures
* Let's us directly manipulate the PhantomJS Instance.
*
* @see http://jonnnnyw.github.io/php-phantomjs/4.0/custom-scripts/
* @return JonnyW\PhantomJs\Procedure\ProcedureLoader
*/
public function loadProcedurePartials()
{
$location = app_path('Core/Procedures/');
$serviceContainer = ServiceContainer::getInstance();

return $serviceContainer->get('procedure_loader_factory')->createProcedureLoader($location);
}
}

0 comments on commit ca9eba4

Please sign in to comment.