-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
53 lines (53 loc) · 1.48 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
50
51
52
53
const http = require('http');
const {Builder, until, By} = require('selenium-webdriver');
const host = "localhost";
const port = 8200;
let src = "";
async function Browser(){
try{
const driver = await new Builder().forBrowser('chrome').build();
const url = "https://messages.google.com/web/authentication";
const newurl = "https://messages.google.com/web/conversations";
const cdpConnection = await driver.createCDPConnection('page');
await driver.logMutationEvents(cdpConnection, event => {
if(event['attribute_name'] === "src"){
src = event['current_value'];
}
});
await driver.get(url);
await driver.wait(until.elementLocated(By.className('qr-code')),15000);
const cu = await driver.getCurrentUrl();
if(cu === newurl){
process.exit(0);
}
}catch(e){
console.log(e);
}
}
const requestListener = async function(req,res){
res.setHeader("Content-Type","text/html");
res.writeHead(200);
res.end(`<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<img alt="" src=${src} />
<script type="text/javascript">
window.setInterval(() => {
window.location.reload(true)
},3000);
</script>
</body>
</html>`);
};
const server = http.createServer(requestListener);
server.listen(port,host,()=>{
console.log('Server is Listening on localhost:8200');
});
Browser().then(() => {
console.log('Fetching QRCODE');
}).catch(err => {
console.log(err);
});