Created
September 9, 2018 16:25
-
-
Save arjunkomath/a5a6a57f3f0d02c78d9c3e69412b00d4 to your computer and use it in GitHub Desktop.
Browser by Techulus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const puppeteer = require('puppeteer'); | |
const app = express(); | |
app.get('/image', async (req, res) => { | |
let browser = null; | |
if (process.env.NODE_ENV === 'production') { | |
browser = await puppeteer.connect({ browserWSEndpoint: 'wss://chrome.browser.techulus.com?API_KEY=YOUR_API_KEY' }) | |
} else { | |
browser = await puppeteer.launch(); | |
} | |
const page = await browser.newPage(); | |
await page.goto('http://www.example.com/'); | |
const screenshot = await page.screenshot(); | |
return res.end(screenshot, 'binary'); | |
}); | |
app.listen(8080); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment