Skip to content

Commit

Permalink
Allow Javascript page scanning for all routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Aug 17, 2023
1 parent 4923f25 commit e7487a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Easily configure which routes to scan, exclude or include specific checks or eve
- [Running the scanner in a local environment](#running-the-scanner-in-a-local-environment)
- [Scanning routes](#scanning-routes)
- [Scanning a single route](#scanning-a-single-route)
- [Scanning a single route in an SPA application](#scanning-a-single-route-in-an-spa-application)
- [Scanning routes in an SPA application](#scanning-routes-in-an-spa-application)
- [Scan model urls](#scan-model-urls)
- [Saving scans into the database](#saving-scans-into-the-database)
- [Listening to events](#listening-to-events)
Expand Down Expand Up @@ -57,7 +57,7 @@ composer require vormkracht10/laravel-seo-scanner

If you want to scan pages that are rendered using Javascript, for example Vue or React, you need to install Puppeteer. You can install it using the following command:

> If you want to know how to scan Javascript rendered pages, check out [Scanning a single route in an SPA application](#scanning-a-single-route-in-an-spa-application). Want to know more about Puppeteer? Check out the [Puppeteer documentation](https://pptr.dev/).
> If you want to know how to scan Javascript rendered pages, check out [Scanning routes in an SPA application](#scanning-routes-in-an-spa-application). Want to know more about Puppeteer? Check out the [Puppeteer documentation](https://pptr.dev/).
```bash
npm install puppeteer
Expand Down Expand Up @@ -222,6 +222,18 @@ return [
'User-Agent' => 'Laravel SEO Scanner/1.0',
],
],

/*
|--------------------------------------------------------------------------
| Javascript rendering
|--------------------------------------------------------------------------
|
| If your website uses javascript to render the content, you can enable
| javascript rendering. This will use a headless browser to render
| the content.
|
*/
'javascript' => false,
];
```

Expand Down Expand Up @@ -315,9 +327,9 @@ php artisan seo:scan-url https://vormkracht10.nl

> Note: The command will only check the SEO score of the url and output the score in the CLI. It will not save the score to the database.
### Scanning a single route in an SPA application
### Scanning routes in an SPA application

If you have an SPA application, you may want to check the SEO score of a specific route. You can do this by running the following command:
If you have an SPA application, you can enable javascript rendering. This will use a headless browser to render the content. To enable javascript rendering, set the `javascript` option to `true` in the config file. You can also enable javascript rendering for a single route by adding the `--javascript` option to the command:

```bash
php artisan seo:scan-url https://vormkracht10.nl --javascript
Expand Down
28 changes: 12 additions & 16 deletions config/seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,17 @@
'headers' => [
'User-Agent' => 'Laravel SEO Scanner/1.0',
],

/*
|--------------------------------------------------------------------------
| Http throttle
|--------------------------------------------------------------------------
|
| Here you can specify the throttle options of the http client. This
| will throttle the requests to the same domain. This is useful
| when you have a lot of routes to check.
|
*/
'throttle' => [
'enabled' => false,
'max_requests' => 10,
'seconds' => 1,
],
],

/*
|--------------------------------------------------------------------------
| Javascript rendering
|--------------------------------------------------------------------------
|
| If your website uses javascript to render the content, you can enable
| javascript rendering. This will use a headless browser to render
| the content.
|
*/
'javascript' => false,
];
2 changes: 1 addition & 1 deletion src/Commands/SeoScan.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function calculateScoreForRoutes(): void
$routes->each(function ($path, $name) {
$this->progress->start();

$seo = Seo::check(url: route($name), progress: $this->progress);
$seo = Seo::check(url: route($name), progress: $this->progress, useJavascript: config('seo.javascript'));

$this->failed += count($seo->getFailedChecks());
$this->success += count($seo->getSuccessfulChecks());
Expand Down

0 comments on commit e7487a4

Please sign in to comment.