-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
73 lines (54 loc) · 1.96 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const readFileSync = require("fs").readFileSync;
const puppeteer = require("puppeteer");
const fs = require('fs');
function evaluateConfigFile() {
const configFile = 'config.js';
// Check if the file exists
if (fs.existsSync(configFile)) {
try {
// Read the contents of the file
const fileContents = fs.readFileSync(configFile, 'utf8');
// Evaluate the contents using eval() - Note: Be cautious with eval() as it can be risky if used with untrusted input.
const configObject = eval(fileContents);
} catch (err) {
console.error('Error reading or evaluating config file:', err);
}
} else {
console.log('Config file does not exist.');
}
}
(async () => {
// Launch the browser and open a new blank page
const browser = await puppeteer.launch({ headless:"new"});
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', interceptedRequest => {
if (interceptedRequest.isInterceptResolutionHandled()) return;
if (
interceptedRequest.url().includes("/api/")
) {
requestLog.push(interceptedRequest.url());
//console.log(`Calling api request: ${interceptedRequest.url()}`)
}
interceptedRequest.continue();
});
evaluateConfigFile()
for (const item of global.config.urls) {
console.log( await visitPage(page, item.url) );
requestLog = [];
}
await browser.close();
})();
let requestLog = [];
async function visitPage(page, url){
// Navigate the page to a URL
console.log("Visiting " + url);
await page.goto(process.env.LOGIN_URL || global.config.loginUrl);
await page.goto(url);
// Set screen size
await page.setViewport({width: 1080, height: 1024});
const selector = ".msk-tabs";
await page.waitForSelector(selector);
await page.waitForNetworkIdle();
return { message: `Successfully loaded ${url}`, apiRequests:requestLog.length };
}