Skip to content

Instantly share code, notes, and snippets.

@hashtafak
Created September 25, 2019 14:56
Show Gist options
  • Save hashtafak/1b6c231019986c3c5f236f9dcb36cf85 to your computer and use it in GitHub Desktop.
Save hashtafak/1b6c231019986c3c5f236f9dcb36cf85 to your computer and use it in GitHub Desktop.
puppeteer get WSEnpoint
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