puppeteer-extra-plugin-devtools
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -23,3 +23,3 @@ 'use strict' | ||
class DevToolsCommon { | ||
constructor (webSocketDebuggerUrl, opts = { }) { | ||
constructor (webSocketDebuggerUrl, opts = {}) { | ||
ow(webSocketDebuggerUrl, ow.string) | ||
@@ -32,3 +32,4 @@ ow(webSocketDebuggerUrl, ow.string.includes('ws://')) | ||
const wsUrlParts = urlParse(this.wsUrl) | ||
this.wsHost = (wsUrlParts.hostname === '127.0.0.1') ? 'localhost' : wsUrlParts.hostname | ||
this.wsHost = | ||
wsUrlParts.hostname === '127.0.0.1' ? 'localhost' : wsUrlParts.hostname | ||
this.wsPort = wsUrlParts.port | ||
@@ -38,3 +39,6 @@ } | ||
async fetchVersion () { | ||
const { body } = await got(`http://${this.wsHost}:${this.wsPort}/json/version`, { json: true }) | ||
const { body } = await got( | ||
`http://${this.wsHost}:${this.wsPort}/json/version`, | ||
{ json: true } | ||
) | ||
return body | ||
@@ -44,3 +48,6 @@ } | ||
async fetchList () { | ||
const { body } = await got(`http://${this.wsHost}:${this.wsPort}/json/list`, { json: true }) | ||
const { body } = await got( | ||
`http://${this.wsHost}:${this.wsPort}/json/list`, | ||
{ json: true } | ||
) | ||
return body | ||
@@ -56,10 +63,14 @@ } | ||
class DevToolsLocal extends DevToolsCommon { | ||
constructor (webSocketDebuggerUrl, opts = { }) { | ||
constructor (webSocketDebuggerUrl, opts = {}) { | ||
super(webSocketDebuggerUrl, opts) | ||
} | ||
get url () { return `http://${this.wsHost}:${this.wsPort}` } | ||
get url () { | ||
return `http://${this.wsHost}:${this.wsPort}` | ||
} | ||
getUrlForPageId (pageId) { | ||
return `${this.url}/devtools/inspector.html?ws=${this.wsHost}:${this.wsPort}/devtools/page/${pageId}` | ||
return `${this.url}/devtools/inspector.html?ws=${this.wsHost}:${ | ||
this.wsPort | ||
}/devtools/page/${pageId}` | ||
} | ||
@@ -83,3 +94,3 @@ } | ||
class DevToolsTunnel extends DevToolsCommon { | ||
constructor (webSocketDebuggerUrl, opts = { }) { | ||
constructor (webSocketDebuggerUrl, opts = {}) { | ||
super(webSocketDebuggerUrl, opts) | ||
@@ -102,12 +113,19 @@ | ||
get url () { return this.tunnel.url } | ||
get url () { | ||
return this.tunnel.url | ||
} | ||
getUrlForPageId (pageId) { | ||
return `https://${this.tunnelHost}/devtools/inspector.html?wss=${this.tunnelHost}/devtools/page/${pageId}` | ||
return `https://${this.tunnelHost}/devtools/inspector.html?wss=${ | ||
this.tunnelHost | ||
}/devtools/page/${pageId}` | ||
} | ||
async create () { | ||
const subdomain = this.opts.subdomain || this._generateSubdomain(this.opts.prefix) | ||
const basicAuth = this.opts.auth.user ? this._createBasicAuth(this.opts.auth.user, this.opts.auth.pass) : null | ||
const serverPort = await getPort(9223) // only preference, will return an available one | ||
const subdomain = | ||
this.opts.subdomain || this._generateSubdomain(this.opts.prefix) | ||
const basicAuth = this.opts.auth.user | ||
? this._createBasicAuth(this.opts.auth.user, this.opts.auth.pass) | ||
: null | ||
const serverPort = await getPort() // only preference, will return an available one | ||
@@ -119,7 +137,10 @@ this.proxyServer = this._createProxyServer(this.wsHost, this.wsPort) | ||
debug('tunnel created.', ` | ||
debug( | ||
'tunnel created.', | ||
` | ||
local: http://${this.wsHost}:${this.wsPort} | ||
proxy: http://localhost:${serverPort} | ||
tunnel: ${this.tunnel.url} | ||
`) | ||
` | ||
) | ||
return this | ||
@@ -137,3 +158,7 @@ } | ||
_generateSubdomain (prefix) { | ||
const rand = randomstring.generate({ length: 10, readable: true, capitalization: 'lowercase' }) | ||
const rand = randomstring.generate({ | ||
length: 10, | ||
readable: true, | ||
capitalization: 'lowercase' | ||
}) | ||
return `${prefix}-${rand}` | ||
@@ -166,3 +191,5 @@ } | ||
_modifyFetchToIncludeCredentials (body) { | ||
if (!body) { return } | ||
if (!body) { | ||
return | ||
} | ||
body = body.replace(`fetch(url).`, `fetch(url, {credentials: 'include'}).`) | ||
@@ -174,3 +201,5 @@ debug('fetch:after', body) | ||
_modifyJSONResponse (body) { | ||
if (!body) { return } | ||
if (!body) { | ||
return | ||
} | ||
debug('list body:before', body) | ||
@@ -184,3 +213,4 @@ body = body.replace(new RegExp(this.wsHost, 'g'), `${this.tunnelHost}`) | ||
_createProxyServer (targetHost = 'localhost', targetPort) { | ||
const proxyServer = new httpProxy.createProxyServer({ // eslint-disable-line | ||
const proxyServer = new httpProxy.createProxyServer({ | ||
// eslint-disable-line | ||
target: { host: targetHost, port: parseInt(targetPort) } | ||
@@ -197,7 +227,15 @@ }) | ||
delete proxyRes.headers['content-length'] | ||
modifyResponse(res, proxyRes.headers['content-encoding'], this._modifyFetchToIncludeCredentials.bind(this)) | ||
modifyResponse( | ||
res, | ||
proxyRes.headers['content-encoding'], | ||
this._modifyFetchToIncludeCredentials.bind(this) | ||
) | ||
} | ||
if (['/json/list', '/json/version'].includes(req.url)) { | ||
delete proxyRes.headers['content-length'] | ||
modifyResponse(res, proxyRes.headers['content-encoding'], this._modifyJSONResponse.bind(this)) | ||
modifyResponse( | ||
res, | ||
proxyRes.headers['content-encoding'], | ||
this._modifyJSONResponse.bind(this) | ||
) | ||
} | ||
@@ -222,7 +260,13 @@ }) | ||
return new Promise((resolve, reject) => { | ||
const tunnel = localtunnel(port, { local_host: host, subdomain }, (err, tunnel) => { | ||
if (err) { return reject(err) } | ||
debug('tunnel:created', tunnel.url) | ||
return resolve(tunnel) | ||
}) | ||
const tunnel = localtunnel( | ||
port, | ||
{ local_host: host, subdomain }, | ||
(err, tunnel) => { | ||
if (err) { | ||
return reject(err) | ||
} | ||
debug('tunnel:created', tunnel.url) | ||
return resolve(tunnel) | ||
} | ||
) | ||
tunnel.on('close', () => { | ||
@@ -229,0 +273,0 @@ // todo: add keep-alive? |
{ | ||
"name": "puppeteer-extra-plugin-devtools", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Make puppeteer browser debugging possible from anywhere (devtools with screencasting on the internet).", | ||
@@ -47,3 +47,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "2783eda8b71df3eb3e360614302c08007d467628" | ||
"gitHead": "fa1fb7b878311b3406316638d0e351cf0d2c3bf2" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35549
528