
Run GoogleChrome/puppeteer as a service.
Usage
Server
$ npm install puppeteer-service --save
const PuppeteerService = ;const koaApp server = ;
😯 If the test
option is set true
like above, you can visit the test page via http://your.host:3000/test/
.
Client
👉 Option 1: Use puppeteer-service-client
$ npm install puppeteer-service-client --save
Use puppeteer-service-client to communicate with the server. It's runnable at both browser and Node.js.
const Run = ; ;
socket and echo
The socket
option specifies a handler for WebSocket data at client side. Correspondingly, the function echo
, which is callable inside the "page runner function", is a built-in function whose responsibility is to transfer data to the right socket connection with the client.
👉 Option 2: Send a request directly
As the following does:
const pageRunner = async { const title = await pagetitle; return info: ;}; ;
⚠️ This way is lightweight but too simple to communicate with the server via WebSocket.
Development
Some commands:
npm start # start npm start -- -p 3000 # port npm start -- -c # cluster npm run debug # debugging mode npm test # test npm test -- -u http://127.0.0.1:3000/run # api url npm test -- -n 10 # batch number
License
Copyright © 2018-present, shenfe