Skip to content

Commit

Permalink
Add support for custom binary/browser script to make adjustments easi…
Browse files Browse the repository at this point in the history
…er/possible. (#162)
  • Loading branch information
ntzrbtr authored and freekmurze committed Feb 22, 2018
1 parent 6993448 commit e5b4de4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ Browsershot::html('Foo')
->setNodeModulePath("/path/to/my/project/node_modules/")
```

### Custom binary path

If you want to use an alternative script source you can set it using the `setBinPath` method.

```php
Browsershot::html('Foo')
->setBinPath("/path/to/my/project/my_script.js")
```

### Custom chrome/chromium executable path

If you want to use an alternative chrome or chromium executable from what is installed by puppeteer you can set it using the `setChromePath` method.
Expand Down
10 changes: 9 additions & 1 deletion src/Browsershot.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Browsershot
protected $npmBinary = null;
protected $nodeModulePath = null;
protected $includePath = '$PATH:/usr/local/bin';
protected $binPath = null;
protected $html = '';
protected $noSandbox = false;
protected $proxyServer = '';
Expand Down Expand Up @@ -79,6 +80,13 @@ public function setIncludePath(string $includePath)
return $this;
}

public function setBinPath(string $binPath)
{
$this->binPath = $binPath;

return $this;
}

public function setNodeModulePath(string $nodeModulePath)
{
$this->nodeModulePath = $nodeModulePath;
Expand Down Expand Up @@ -471,7 +479,7 @@ protected function callBrowser(array $command)

$setNodePathCommand = $this->getNodePathCommand($nodeBinary);

$binPath = __DIR__.'/../bin/browser.js';
$binPath = $this->binPath ?: __DIR__.'/../bin/browser.js';

$fullCommand =
$setIncludePathCommand.' '
Expand Down
14 changes: 13 additions & 1 deletion tests/BrowsershotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public function it_can_set_another_node_binary()
$targetPath = __DIR__.'/temp/testScreenshot.png';

Browsershot::html('Foo')
->setNodeBinary('non-existant/bin/wich/causes/an/exception')
->setBinPath(__DIR__.'/../browser.js')
->save($targetPath);
}

Expand All @@ -477,6 +477,18 @@ public function it_can_set_another_chrome_executable_path()
->save($targetPath);
}

/** @test */
public function it_can_set_another_bin_path()
{
$this->expectException(ProcessFailedException::class);

$targetPath = __DIR__.'/temp/testScreenshot.png';

Browsershot::html('Foo')
->setChromePath('non-existant/bin/wich/causes/an/exception')
->save($targetPath);
}

/** @test */
public function it_can_set_the_include_path_and_still_works()
{
Expand Down

0 comments on commit e5b4de4

Please sign in to comment.