-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.js
More file actions
58 lines (46 loc) · 1.7 KB
/
example.js
File metadata and controls
58 lines (46 loc) · 1.7 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
const puppeteer = require('puppeteer')
const fs = require('fs')
const path = require('path')
const process = require('process')
// Get the CLI args and strip off the first two elements. See: https://nodejs.org/en/knowledge/command-line/how-to-parse-command-line-arguments/
var cliArgs = process.argv.slice(2)
if (cliArgs.length != 1) {
var cliName = path.basename(__filename)
console.log("Usage: " + cliName + " <full_path_to_jstack>")
process.exit(1)
}
var jstackFilePath = cliArgs[0]
try {
if (!fs.existsSync(jstackFilePath)) {
console.log("No such file: " + jstackFilePath)
process.exit(2)
}
} catch (err) {
console.error(err)
processs.exit(3)
}
(async () => {
const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']})
const page = await browser.newPage()
const url_path_to_jstack_review = "file:///" + process.cwd() + "/index.html"
await page.goto(url_path_to_jstack_review)
// get the selector input type=file (for upload file)
await page.waitForSelector('input[type=file]')
await page.waitFor(1000)
// get the ElementHandle of the selector above
const inputUploadHandle = await page.$('input[type=file]')
// Sets the value of the file input
inputUploadHandle.uploadFile(jstackFilePath)
// wait for selector that contains the uploaded file URL
await page.waitForSelector('#tda_1_dumpFile')
await page.waitFor(1000)
// This block will make Puppeteer press jstack-review's 'End tour' button for me.
const [button] = await page.$x("//button[contains(., 'End tour')]")
if (button) {
await button.click()
}
const html = await page.content()
fs.writeFileSync("jstack.html", html)
await browser.close()
})()