Skip to content

Commit f81c560

Browse files
SanderEliasjorgeucano
authored andcommitted
feat(Scully config): adds an option to set the puppeteer launch options (#184)
* feat(scully config): adds an optin to set the pupperteer launch options closes #181 * docs(scully-configuration): add link to lauchOptions docs
1 parent 3445f3a commit f81c560

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

docs/scully-configuration.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ If you are starting to use scully we highly recommend read the [Getting Started]
77
also if you want to enhance you project made with scully, visit the [Utils](utils.md) section and see
88
or teach to the community how to combine scully with others tools.
99

10-
- [`ScullyConfig` Interface](#scullyconfig-interface)
11-
- [projectRoot](#projectRoot)
12-
- [homeFolder](#homeFolder)
13-
- [outDir](#outDir)
14-
- [distFolder](#distFolder)
15-
- [routes](#routes)
16-
- [extraRoutes](#extraRoutes)
17-
- [appPort](#appPort)
18-
- [staticport](#staticport)
10+
- [Scully Configuration](#scully-configuration)
11+
- [`ScullyConfig` Interface](#scullyconfig-interface)
12+
- [scullyConfig properties explained](#scullyconfig-properties-explained)
13+
- [projectRoot](#projectroot)
14+
- [homeFolder](#homefolder)
15+
- [outDir](#outdir)
16+
- [distFolder](#distfolder)
17+
- [routes](#routes)
18+
- [handled Routes](#handled-routes)
19+
- [unhandled Routes](#unhandled-routes)
20+
- [extraRoutes](#extraroutes)
21+
- [appPort](#appport)
22+
- [staticport](#staticport)
23+
- [puppeteerLaunchOptions](#puppeteerlaunchoptions)
1924

2025
## `ScullyConfig` Interface
2126

@@ -29,11 +34,14 @@ export interface ScullyConfig {
2934
extraRoutes?: string[];
3035
appPort: number;
3136
staticport: number;
37+
puppeteerLaunchOptions?: LaunchOptions;
3238
}
3339
```
3440

3541
`ScullyConfig` interface provide the parameters to configure how scully works in your project.
3642

43+
## scullyConfig properties explained
44+
3745
### projectRoot
3846

3947
`projectRoot` is reference to the path to the project where scully will intervene.
@@ -87,7 +95,7 @@ I you want to know more about plugins go to [Plugins](plugins.md) section.
8795

8896
### extraRoutes
8997

90-
The `extraRoutes` property allow to the developer add an array of handled routes to discover by Scully.
98+
The `extraRoutes` property allow to the developer add an array of unhandled routes to discover by Scully.
9199
These can be routes that exist in AngularJS, or in React, or in whatever Framework's router.
92100

93101
It can be handle `:string`, `Promise<string>` or `Promise<Array<string>>`
@@ -110,4 +118,11 @@ which will serve static files compiled by Scully.
110118

111119
The port by default is: `1668`
112120

121+
### puppeteerLaunchOptions
122+
123+
When in a restricted environment there is a change the default options for puppeteer won't work. In such a case
124+
this option can override the puppeteerLaunchOptions with settings that match this environment.
125+
Word of warning, some settings might interfer with the way Scully is working, creating errornous results.
126+
Follow [this link](https://pptr.dev/#?product=Puppeteer&version=v2.0.0&show=api-puppeteerlaunchoptions) for more information
127+
113128
[Full Documentation ➡️](scully.md)

scully/renderPlugins/launchedBrowser.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Observable} from 'rxjs';
33
import {shareReplay, take} from 'rxjs/operators';
44
import {log} from '../utils/log';
55
import * as yargs from 'yargs';
6+
import {scullyConfig} from '../utils/config';
67

78
const {showBrowser} = yargs
89
.boolean('sb')
@@ -14,14 +15,13 @@ const launched = obsBrowser().pipe(shareReplay({refCount: false, bufferSize: 1})
1415
export const launchedBrowser: () => Promise<Browser> = () => launched.pipe(take(1)).toPromise();
1516
let browser: Browser;
1617

17-
function obsBrowser(
18-
options: LaunchOptions = {
19-
headless: !showBrowser,
20-
// dumpio: true,
21-
args: ['--no-sandbox', '--disable-setuid-sandbox'],
18+
function obsBrowser(options: LaunchOptions = scullyConfig.puppeteerLaunchOptions || {}): Observable<Browser> {
19+
if (showBrowser) {
20+
options.headless = false;
2221
}
23-
): Observable<Browser> {
24-
const { SCULLY_PUPPETEER_EXECUTABLE_PATH } = process.env;
22+
// option.args= ['--no-sandbox', '--disable-setuid-sandbox'],
23+
24+
const {SCULLY_PUPPETEER_EXECUTABLE_PATH} = process.env;
2525
if (SCULLY_PUPPETEER_EXECUTABLE_PATH) {
2626
log(`Launching puppeteer with executablePath ${SCULLY_PUPPETEER_EXECUTABLE_PATH}`);
2727
options.executablePath = SCULLY_PUPPETEER_EXECUTABLE_PATH;

scully/utils/interfacesandenums.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {LaunchOptions} from 'puppeteer';
2+
13
export enum RouteTypes {
24
json = 'json',
35
contentFolder = 'contentFolder',
@@ -14,6 +16,7 @@ export interface ScullyConfig {
1416
extraRoutes?: string[];
1517
appPort: number;
1618
staticport: number;
19+
puppeteerLaunchOptions?: LaunchOptions;
1720
}
1821

1922
interface RouteConfig {

0 commit comments

Comments
 (0)