Puppeteer API Server
Overview
This is a Node.js-based API server that allows dynamic execution of Puppeteer scripts for web scraping and automation tasks.
Features
- Dynamic script execution via REST API
- Puppeteer-powered web scraping
- Containerized deployment
Prerequisites
- Docker
- Docker Compose
- Node.js 18+
Installation
Clone the Repository
git clone <your-repository-url>
cd puppeteer-api-server
Build and Run
Using Docker Compose:
docker-compose up -d
API Endpoint
Run Script
- URL:
http://localhost:44444/run-script
- Method: POST
- Request Body:
{ "script": "scriptName.js", "url": "/path/to/page" }
Project Structure
server.js
: Express server handling script executionDockerfile
: Docker configuration for the applicationdocker-compose.yaml
: Docker Compose configurationscripts/
: Directory for custom Puppeteer scriptspackage.json
: Node.js project dependencies
Writing Custom Scripts
Place Puppeteer scripts in the scripts/
directory. Each script should export an async function that takes browser
and url
as parameters.
Example script structure:
module.exports = async (browser, url) => {
const page = await browser.newPage();
await page.goto(url);
// Perform scraping or automation tasks
return results;
};
Security
- Scripts run in a sandboxed environment
- URL normalization prevents arbitrary website access
- Runs with minimal Docker container privileges
Logging
Server logs are output to the console, providing insights into script execution and potential errors.
Troubleshooting
- Ensure Docker is running
- Check container logs:
docker-compose logs puppeteer
- Verify script syntax and Puppeteer compatibility
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
This project is licensed under the GNU General Public License v3.0 (GPL-3.0). See the LICENSE file for details.
Disclaimer
This tool is for educational and authorized testing purposes only. Always respect website terms of service and legal guidelines when web scraping.
Author
[Il Gigante/Tana del Gigante]