This repository has been archived by the owner on Sep 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lukas Alexander Kienzl
committed
Apr 6, 2018
0 parents
commit 9d96819
Showing
11 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
; This file is for unifying the coding style for different editors and IDEs. | ||
; More information at http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 4 | ||
indent_style = space | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Path-based git attributes | ||
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html | ||
|
||
# Ignore all test and documentation with "export-ignore". | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/tests export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build | ||
composer.lock | ||
docs | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
preset: laravel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
language: php | ||
|
||
php: | ||
- 7.1 | ||
- 7.2 | ||
|
||
before_script: | ||
- travis_retry composer self-update | ||
- travis_retry composer update --no-interaction --prefer-dist | ||
|
||
script: | ||
- composer test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# A Chrome Headless wrapper for Laravel | ||
[![Build Status](https://img.shields.io/travis/helloiamlukas/laravel-chrome/master.svg?style=flat-square)](https://travis-ci.org/helloiamlukas/chrome-php) | ||
[![StyleCI](https://styleci.io/repos/128383656/shield?branch=master)](https://styleci.io/repos/19386515) | ||
|
||
Get the DOM of any webpage by using headless Chrome. | ||
|
||
# Requirements | ||
This package requires a stable version of Google Chrome (v63 or higher). | ||
|
||
If you want to install it on Ubuntu 16.04 you can do it like this: | ||
``` | ||
sudo apt-get update | ||
sudo apt-get install -y libappindicator1 fonts-liberation | ||
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb | ||
sudo dpkg -i google-chrome*.deb | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "helloiamlukas/laravel-chrome", | ||
"description": "A Laravel Wrapper for Chrome Headless. Get the DOM of any webpage.", | ||
"homepage": "https://github.com/helloiamlukas/laravel-chrome", | ||
"keywords": | ||
[ | ||
"laravel", | ||
"webpage", | ||
"dom", | ||
"chrome", | ||
"headless" | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"php": "^7.1", | ||
"helloiamlukas/chrome-php": "^1.0" | ||
}, | ||
"require-dev": { | ||
"orchestra/testbench": "^3.6", | ||
"phpunit/phpunit": "^6.1|^7.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"ChromeHeadless\\Laravel\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"ChromeHeadless\\Laravel\\Test\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit" | ||
}, | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"ChromeHeadless\\Laravel\\ChromeHeadlessServiceProvider" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
return [ | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Chrome Path | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Manually set the path where Google Chrome is installed. | ||
| | ||
*/ | ||
'exec_path' => 'google-chrome', | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| User Agent | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Change the user agent that will be used by Google Chrome. | ||
| | ||
*/ | ||
'user_agent' => null, | ||
/* | ||
|-------------------------------------------------------------------------- | ||
| Timeout | ||
|-------------------------------------------------------------------------- | ||
| | ||
| Specify a timeout in seconds. | ||
| (null = no timeout) | ||
| | ||
*/ | ||
'timeout' => null, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="ChromeHeadless Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace ChromeHeadless\Laravel; | ||
|
||
use ChromeHeadless\ChromeHeadless; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class ChromeHeadlessServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Bootstrap the application services. | ||
*/ | ||
public function boot() | ||
{ | ||
$this->publishes([ | ||
__DIR__.'/../config/chrome.php' => config_path('chrome.php'), | ||
], 'config'); | ||
} | ||
|
||
/** | ||
* Register the application services. | ||
*/ | ||
public function register() | ||
{ | ||
$this->mergeConfigFrom(__DIR__.'/../config/chrome.php', 'chrome'); | ||
|
||
$this->app->resolving(ChromeHeadless::class, function (ChromeHeadless $chrome) { | ||
return $chrome->setChromePath($this->app->config->get('chrome.exec_path')) | ||
->setUserAgent($this->app->config->get('chrome.user_agent')) | ||
->setTimeout($this->app->config->get('chrome.timeout')); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace ChromeHeadless\Test; | ||
|
||
use ChromeHeadless\ChromeHeadless; | ||
use ChromeHeadless\Laravel\ChromeHeadlessServiceProvider; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
class ChromeHeadlessServiceProviderTest extends TestCase | ||
{ | ||
protected function getPackageProviders($app) | ||
{ | ||
return [ChromeHeadlessServiceProvider::class]; | ||
} | ||
|
||
/** @test */ | ||
public function it_can_set_a_custom_user_agent() | ||
{ | ||
$user_agent = 'NiceUserAgent/1.0'; | ||
|
||
$this->app->config->set('chrome.user_agent', $user_agent); | ||
|
||
$command = ChromeHeadless::url('https://example.com')->setUserAgent($user_agent)->createCommand(); | ||
|
||
$this->assertContains('--user-agent="'.$user_agent.'"', $command); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_set_a_custom_chrome_path() | ||
{ | ||
$chrome_path = 'google-chrome-stable'; | ||
|
||
$this->app->config->set('chrome.exec_path', $chrome_path); | ||
|
||
$command = ChromeHeadless::url('https://example.com')->setUserAgent($chrome_path)->createCommand(); | ||
|
||
$this->assertContains('--user-agent="'.$chrome_path.'"', $command); | ||
} | ||
} |