Created
July 19, 2022 13:03
-
-
Save ajaykarthikr/b8ee176e994c249d74f6ff5c4708865e to your computer and use it in GitHub Desktop.
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 chromium = require('chrome-aws-lambda'); | |
const playwright = require('playwright-core'); | |
const serverless = require("serverless-http"); | |
const express = require("express"); | |
const app = express(); | |
app.get("/", async function (req, res) { | |
let browser = null; | |
var resp = {} | |
try { | |
const browser = await playwright.chromium.launch({ | |
args: chromium.args, | |
executablePath: await chromium.executablePath, | |
headless: chromium.headless, | |
}); | |
let page = await browser.newPage(); | |
await page.goto('https://google.com'); | |
const data = await page.title() | |
resp = res.status(200).json({ | |
data: data | |
}) | |
} catch (error) { | |
resp = res.status(400).json({ | |
error: error | |
}) | |
} finally { | |
if (browser !== null) { | |
await browser.close(); | |
} | |
} | |
return res.status(200).json(resp); | |
}); | |
module.exports.handler = serverless(app); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment