Skip to content

Commit 4bdf39c

Browse files
authored
Merge pull request #21 from oblakstudio/feat/nest10
Bumped dependency versions for nestJS and puppeteer
2 parents 8c02dc0 + f639e13 commit 4bdf39c

12 files changed

+4494
-3892
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ indent_size = 2
1414

1515
[tsconfig.json]
1616
indent_size = 2
17+
18+
[*.md]
19+
trim_trailing_whitespace = false

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20

README.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@
33
# nestjs-puppeteer
44
Puppeteer module for Nest framework (node.js)
55

6-
![npm](https://img.shields.io/npm/v/nestjs-puppeteer)
6+
[![npm](https://img.shields.io/npm/v/nestjs-puppeteer?logo=npm)](https://npmjs/package/nestjs-puppeteer)
77
![npm](https://img.shields.io/npm/dm/nestjs-puppeteer)
88
![GitHub](https://img.shields.io/github/license/oblakstudio/nestjs-puppeteer)
9-
[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
9+
[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
10+
![Puppeter Peer Dep](https://img.shields.io/npm/dependency-version/nestjs-puppeteer/peer/@nestjs/core?logo=nestjs&logoColor=E42844)
11+
![NestJS Peer Dep](https://img.shields.io/npm/dependency-version/nestjs-puppeteer/peer/puppeteer?logo=puppeteer&logoColor=%23fff)
1012

1113
</div>
1214

13-
## Usage
15+
Headless Chrome provider for [NestJS](https://nestjs.com/), enabling easy integration of Puppeteer into your application.
16+
17+
> [!IMPORTANT]
18+
> Chrome introduces the _"New Headless"_ mode in version 112. Most of `puppeteer-extra` plugins are **NOT COMPATIBLE** with this mode. If you want to use `puppeteer-extra` plugins, you need to define `headless: true` in the module configuration.
19+
>
20+
> You can read more about the new headless mode [here](https://developer.chrome.com/docs/chromium/new-headless).
21+
22+
## Installation
1423

1524
To begin using it, we first install the required dependencies.
1625

1726
```sh
18-
$ npm install --save nestjs-puppeteer puppeteer-extra
27+
$ npm install --save nestjs-puppeteer puppeteer-extra puppeteer
1928
```
29+
## Usage
2030

2131
Once the installation process is complete we can import the ``PuppeteerModule`` into the root ``AppModule``
2232

@@ -26,7 +36,7 @@ import { PuppeteerModule } from 'nestjs-puppeteer';
2636

2737
@Module({
2838
imports: [
29-
PuppeteerModule.forRoot(),
39+
PuppeteerModule.forRoot({ headless: 'new' }),
3040
],
3141
})
3242
export class AppModule {}
@@ -40,6 +50,7 @@ The ``forRoot()`` method supports all the configuration properties exposed by th
4050
| ``name`` | Browser name |
4151
| ``plugins`` | An array of ``puppeteer-extra`` plugins |
4252
| ``isGlobal`` | Should the module be registered in the global context |
53+
| ``headless`` | `new` for the [New Headless](https://developer.chrome.com/docs/chromium/new-headless) mode, or `true`/`false` |
4354

4455
Once this is done, the Puppeteer ``Browser`` instance will be available for injection in any of the providers in the application.
4556

@@ -48,7 +59,7 @@ import { Browser } from 'puppeteer';
4859

4960
@Module({
5061
imports: [
51-
PuppeteerModule.forRoot(),
62+
PuppeteerModule.forRoot({ headless: 'new' }),
5263
],
5364
})
5465
export class AppModule {
@@ -68,7 +79,7 @@ import { PuppeteerModule } from 'nestjs-puppeteer';
6879

6980
@Module({
7081
imports: [
71-
PuppeteerModule.forRoot(),
82+
PuppeteerModule.forRoot({ headless: 'new' }),
7283
PuppeteerModule.forFeature(['page1', 'page2']),
7384
],
7485
})
@@ -82,7 +93,7 @@ import { Page } from 'puppeteer';
8293

8394
@Module({
8495
imports: [
85-
PuppeteerModule.forRoot(),
96+
PuppeteerModule.forRoot({ headless: 'new' }),
8697
PuppeteerModule.forFeature(['page1', 'page2']),
8798
],
8899
})
@@ -125,14 +136,15 @@ PuppeteerModule.forRootAsync({
125136
useClass: PuppeteerConfigService,
126137
})
127138
```
128-
The construction above will instantiate ``PuppeteerConfigService`` inside ``PuppeteerModule`` and use it to provide an options object by calling ``createPuppeteerOptions()``. Note that this means that the ``PuppeteerConfigService`` has to implement the ``PuppeteerOptionsFactory`` interface, as shown below:
139+
The construction above will instantiate ``PuppeteerConfigService`` inside ``PuppeteerModule`` and use it to provide an options object by calling ``createPuppeteerOptions()``.
140+
Note that this means that the ``PuppeteerConfigService`` has to implement the ``PuppeteerOptionsFactory`` interface, as shown below:
129141

130142
```ts
131143
@Injectable()
132144
class PuppeteerConfigService implements PuppeteerOptionsFactory {
133145
createPuppeteerOptions(): PuppeteerNodeLaunchOptions {
134146
return {
135-
headless: false,
147+
headless: 'new',
136148
};
137149
}
138150
}

lib/puppeteer-core.module.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,14 @@ export class PuppeteerCoreModule implements OnApplicationShutdown {
8282
};
8383
const browserProvider = {
8484
provide: getBrowserToken(options),
85-
useFactory: async(options: PuppeteerModuleOptions) => {
85+
useFactory: async (options: PuppeteerModuleOptions) => {
8686
return await puppeteer.launch(options);
8787
},
8888
inject: [PUPPETEER_MODULE_OPTIONS],
8989
};
9090
const asyncProviders = this.createAsyncProviders(options);
9191

92-
const providers = [
93-
...asyncProviders,
94-
pluginProvider,
95-
browserProvider,
96-
];
92+
const providers = [...asyncProviders, pluginProvider, browserProvider];
9793

9894
const exports = [browserProvider];
9995

@@ -108,7 +104,7 @@ export class PuppeteerCoreModule implements OnApplicationShutdown {
108104
const browser = this.moduleRef.get<Browser>(getBrowserToken(this.options));
109105

110106
try {
111-
if (browser && browser.isConnected()) {
107+
if (browser && browser.connected) {
112108
this.logger.log('Closing browser...');
113109
await browser.close();
114110
}
@@ -131,7 +127,7 @@ export class PuppeteerCoreModule implements OnApplicationShutdown {
131127
{
132128
provide: useClass,
133129
useClass,
134-
}
130+
},
135131
];
136132
}
137133

0 commit comments

Comments
 (0)