-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (39 loc) · 1.06 KB
/
index.js
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
const puppeteer = require('puppeteer');
const StaticServer = require('static-server');
async function automateBrowser({port}) {
const browser = await puppeteer.launch({
headless: false
});
const page = await browser.newPage();
await page.setRequestInterceptionEnabled(true);
page.on('request', request => {
const URLToIntercept = 'https://forms.hubspot.com/embed/v3/form/2059467/2e1a1b5b-27bb-447d-aac4-0b87c1e88fec?callback=hs_reqwest_0&hutk=';
if (request.url === URLToIntercept) {
request.continue({
url: `http://127.0.0.1:${port}/form.txt`
});
} else {
request.continue();
}
});
await page.goto('https://www.sitepen.com/site/contact.html');
await browser.close();
process.exit();
}
function setupMockServer() {
return new Promise(resolve => {
const server = new StaticServer({
rootPath: './mocks',
port: 8080
});
server.start(() => {
console.log('Mock server started on port', server.port);
resolve(server);
});
});
}
async function main() {
const {port} = await setupMockServer();
automateBrowser({port});
}
main();