File size: 962 Bytes
1f4041b
 
e1f90a1
 
1f4041b
 
 
 
 
 
e1f90a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f4041b
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const app = require("express")();

const chromium = require('chrome-aws-lambda');
const puppeteer = require('puppeteer-core');

app.get("/", (req, res) => {
  res.send('Hello AuthCode')
})

app.get("/api", async (req, res) => {
  const browser = await puppeteer.launch({
    args: chromium.args,
    executablePath: process.env.CHROME_EXECUTABLE_PATH || await chromium.executablePath,
    headless: true,
  });

  const page = await browser.newPage();

  await page.goto("https://liaobots.work/");
  await page.click('label.button');
  await page.waitForNavigation();
  await page.waitForTimeout(2000);

  // Execute JavaScript code in the context of the page
  const value = await page.evaluate(() => {
      // Retrieve the value from localStorage
      return localStorage.getItem('authCode');
  });


  await browser.close();

  res.send(value);
  
});

app.listen(process.env.PORT || 3000, () => {
  console.log("Server started");
});

module.exports = app;