Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Feat: support for puppeteer-extra plugins #149

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,27 @@ try {

Instead, a `Node\Exception` will be thrown, the Node process will stay alive and usable.

### Puppeteer plugins

To use puppeteer-extra plugins add them to your project:
```shell
npm install puppeteer puppeteer-extra puppeteer-extra-plugin-stealth
```

Then override js inclusion with js_extra option
```php
$puppeteer = new Puppeteer([
'js_extra' => /** @lang JavaScript */ "
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());
instruction.setDefaultResource(puppeteer);
"
]);
```



## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.
Expand Down
3 changes: 3 additions & 0 deletions src/Puppeteer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Puppeteer extends AbstractEntryPoint

// Logs the output of Browser's console methods (console.log, console.debug, etc...) to the PHP logger
'log_browser_console' => false,

//Custom js to load puppeteer-extra plugins
'js_extra' => ''
];

/**
Expand Down
10 changes: 7 additions & 3 deletions src/PuppeteerConnectionDelegate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const puppeteer = require('puppeteer'),
{ConnectionDelegate} = require('@nesk/rialto'),
const {ConnectionDelegate} = require('@nesk/rialto'),
Logger = require('@nesk/rialto/src/node-process/Logger'),
ConsoleInterceptor = require('@nesk/rialto/src/node-process/NodeInterceptors/ConsoleInterceptor'),
StandardStreamsInterceptor = require('@nesk/rialto/src/node-process/NodeInterceptors/StandardStreamsInterceptor');
Expand All @@ -28,7 +27,12 @@ class PuppeteerConnectionDelegate extends ConnectionDelegate
* @inheritdoc
*/
async handleInstruction(instruction, responseHandler, errorHandler) {
instruction.setDefaultResource(puppeteer);
if (this.options.js_extra) {
eval(this.options.js_extra);
} else {
const puppeteer = require('puppeteer');
instruction.setDefaultResource(puppeteer);
}

let value = null;

Expand Down