Created
September 25, 2019 14:56
-
-
Save hashtafak/1b6c231019986c3c5f236f9dcb36cf85 to your computer and use it in GitHub Desktop.
puppeteer get WSEnpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const debug = require('debug')('spb:lib:pptEx'); | |
function getWSEndpoint(port) { | |
return new Promise((resolve, reject) => { | |
http | |
.get(`http://localhost:${port}/json/version`, (res) => { | |
res.setEncoding('utf8'); | |
let rawData = ''; | |
res.on('data', (chunk) => { | |
rawData += chunk; | |
}); | |
res.on('end', () => { | |
try { | |
const WSEndpoint = JSON.parse(rawData).webSocketDebuggerUrl || 0; | |
debug(`WSEndpoint: ${WSEndpoint}`); | |
resolve(WSEndpoint); | |
} catch (e) { | |
debug(`getWSEndpoint Error: ${e.message}`); | |
reject(e); | |
} | |
}); | |
}) | |
.on('error', (e) => { | |
debug(`getWSEndpoint Error: ${e.message}`); | |
reject(e); | |
}); | |
}); | |
} | |
module.exports = { getWSEndpoint }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment