From ff8dfbcabac9aab6fd95f56f5ebced5b5eac259c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zsi?= Date: Mon, 6 Jul 2020 18:53:54 +0300 Subject: [PATCH] Allow localtunnel options (#135) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: berstend̡̲̫̹̠̖͚͓̔̄̓̐̄͛̀͘ --- .../lib/RemoteDevTools.js | 37 +++--- .../package.json | 2 +- .../puppeteer-extra-plugin-devtools/readme.md | 1 + .../test/headless.js | 18 +++ yarn.lock | 107 ++++-------------- 5 files changed, 57 insertions(+), 108 deletions(-) diff --git a/packages/puppeteer-extra-plugin-devtools/lib/RemoteDevTools.js b/packages/puppeteer-extra-plugin-devtools/lib/RemoteDevTools.js index ea286858..e071a57c 100644 --- a/packages/puppeteer-extra-plugin-devtools/lib/RemoteDevTools.js +++ b/packages/puppeteer-extra-plugin-devtools/lib/RemoteDevTools.js @@ -100,7 +100,8 @@ class DevToolsTunnel extends DevToolsCommon { return { prefix: 'devtools-tunnel', subdomain: null, - auth: { user: null, pass: null } + auth: { user: null, pass: null }, + localtunnel: {} } } @@ -122,7 +123,13 @@ class DevToolsTunnel extends DevToolsCommon { this.proxyServer = this._createProxyServer(this.wsHost, this.wsPort) this.server = await this._createServer(serverPort, basicAuth) - this.tunnel = await this._createTunnel(this.wsHost, serverPort, subdomain) + this.tunnel = await this._createTunnel({ + local_host: this.wsHost, + port: serverPort, + subdomain, + ...this.opts.localtunnel + }) + this.tunnelHost = urlParse(this.tunnel.url).hostname debug( @@ -241,24 +248,16 @@ class DevToolsTunnel extends DevToolsCommon { return server } - async _createTunnel(host, port, subdomain = null) { - 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) - } - ) - tunnel.on('close', () => { - // todo: add keep-alive? - debug('tunnel:close') - }) + async _createTunnel(options) { + const tunnel = await localtunnel(options) + + tunnel.on('close', () => { + // todo: add keep-alive? + debug('tunnel:close') }) + + debug('tunnel:created', tunnel.url) + return tunnel } } diff --git a/packages/puppeteer-extra-plugin-devtools/package.json b/packages/puppeteer-extra-plugin-devtools/package.json index 5b311270..4bf1b4f6 100644 --- a/packages/puppeteer-extra-plugin-devtools/package.json +++ b/packages/puppeteer-extra-plugin-devtools/package.json @@ -38,7 +38,7 @@ "http-auth": "^3.2.3", "http-proxy": "^1.17.0", "http-proxy-response-rewrite": "^0.0.1", - "localtunnel": "^1.9.0", + "localtunnel": "^2.0.0", "ow": "^0.4.0", "puppeteer-extra-plugin": "^3.1.4", "randomstring": "^1.1.5", diff --git a/packages/puppeteer-extra-plugin-devtools/readme.md b/packages/puppeteer-extra-plugin-devtools/readme.md index 3e8602f3..9f8a46d5 100644 --- a/packages/puppeteer-extra-plugin-devtools/readme.md +++ b/packages/puppeteer-extra-plugin-devtools/readme.md @@ -74,6 +74,7 @@ Type: `function (opts)` - `opts.auth.user` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Username (default: 'user') - `opts.auth.pass` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Password (will be generated if not provided) - `opts.prefix` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** The prefix to use for the localtunnel.me subdomain (default: 'devtools-tunnel') + - `opts.localtunnel` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Advanced options to pass to [localtunnel](https://github.com/localtunnel/localtunnel#options) Example: diff --git a/packages/puppeteer-extra-plugin-devtools/test/headless.js b/packages/puppeteer-extra-plugin-devtools/test/headless.js index c0e73964..54cb47e5 100644 --- a/packages/puppeteer-extra-plugin-devtools/test/headless.js +++ b/packages/puppeteer-extra-plugin-devtools/test/headless.js @@ -24,3 +24,21 @@ test('will create a tunnel', async t => { }) t.true(true) }) + +test('will create a tunnel with custom localtunnel options', async t => { + const puppeteer = require('puppeteer-extra') + const devtools = require('puppeteer-extra-plugin-devtools')({ + auth: { user: 'francis', pass: 'president' }, + localtunnel: { + host: 'https://tunnel.datahub.at' + } + }) + puppeteer.use(devtools) + + await puppeteer.launch({ args: PUPPETEER_ARGS }).then(async browser => { + const tunnel = await devtools.createTunnel(browser) + t.true(tunnel.url.includes('.tunnel.datahub.at')) + browser.close() + }) + t.true(true) +}) diff --git a/yarn.lock b/yarn.lock index 7d254363..1dceecd5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2719,11 +2719,6 @@ camelcase@^2.0.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-2.1.1.tgz#7c1d16d679a1bbe59ca02cacecfb011e201f5a1f" integrity sha1-fB0W1nmhu+WcoCys7PsBHiAfWh8= -camelcase@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-3.0.0.tgz#32fc4b9fcdaf845fcdf7e73bb97cac2261f0ab0a" - integrity sha1-MvxLn82vhF/N9+c7uXysImHwqwo= - camelcase@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd" @@ -2888,15 +2883,6 @@ cli-width@^2.0.0: resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639" integrity sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk= -cliui@^3.2.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/cliui/-/cliui-3.2.0.tgz#120601537a916d29940f934da3b48d585a39213d" - integrity sha1-EgYBU3qRbSmUD5NNo7SNWFo5IT0= - dependencies: - string-width "^1.0.1" - strip-ansi "^3.0.1" - wrap-ansi "^2.0.0" - cliui@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/cliui/-/cliui-4.1.0.tgz#348422dbe82d800b3022eef4f6ac10bf2e4d1b49" @@ -3420,7 +3406,7 @@ decamelize-keys@^1.0.0: decamelize "^1.1.0" map-obj "^1.0.0" -decamelize@^1.1.0, decamelize@^1.1.1, decamelize@^1.1.2, decamelize@^1.2.0: +decamelize@^1.1.0, decamelize@^1.1.2, decamelize@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" integrity sha1-9lNNFRSCabIDUue+4m9QH5oZEpA= @@ -5406,11 +5392,6 @@ invariant@^2.2.2: dependencies: loose-envify "^1.0.0" -invert-kv@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6" - integrity sha1-EEqOSqym09jNFXqO+L+rLXo//bY= - invert-kv@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02" @@ -6037,13 +6018,6 @@ lazystream@^1.0.0: dependencies: readable-stream "^2.0.5" -lcid@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/lcid/-/lcid-1.0.0.tgz#308accafa0bc483a3867b4b6f2b9506251d1b835" - integrity sha1-MIrMr6C8SDo4Z7S28rlQYlHRuDU= - dependencies: - invert-kv "^1.0.0" - lcid@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/lcid/-/lcid-2.0.0.tgz#6ef5d2df60e52f82eb228a4c373e8d1f397253cf" @@ -6152,15 +6126,15 @@ load-json-file@^5.2.0, load-json-file@^5.3.0: strip-bom "^3.0.0" type-fest "^0.3.0" -localtunnel@^1.9.0: - version "1.9.2" - resolved "https://registry.yarnpkg.com/localtunnel/-/localtunnel-1.9.2.tgz#0012fcabc29cf964c130a01858768aa2bb65b5af" - integrity sha512-NEKF7bDJE9U3xzJu3kbayF0WTvng6Pww7tzqNb/XtEARYwqw7CKEX7BvOMg98FtE9es2CRizl61gkV3hS8dqYg== +localtunnel@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/localtunnel/-/localtunnel-2.0.0.tgz#2ea71174fa80e34cce91b2a7ce416e6a57d9ff7c" + integrity sha512-g6E0aLgYYDvQDxIjIXkgJo2+pHj3sGg4Wz/XP3h2KtZnRsWPbOQY+hw1H8Z91jep998fkcVE9l+kghO+97vllg== dependencies: axios "0.19.0" debug "4.1.1" openurl "1.1.1" - yargs "6.6.0" + yargs "13.3.0" locate-path@^2.0.0: version "2.0.0" @@ -7186,13 +7160,6 @@ os-homedir@^1.0.0: resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" integrity sha1-/7xJiDNuDoM94MFox+8VISGqf7M= -os-locale@^1.4.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-1.4.0.tgz#20f9f17ae29ed345e8bde583b13d2009803c14d9" - integrity sha1-IPnxeuKe00XoveWDsT0gCYA8FNk= - dependencies: - lcid "^1.0.0" - os-locale@^3.0.0: version "3.1.0" resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-3.1.0.tgz#a802a6ee17f24c10483ab9935719cef4ed16bf1a" @@ -8974,7 +8941,7 @@ string-template@~0.2.1: resolved "https://registry.yarnpkg.com/string-template/-/string-template-0.2.1.tgz#42932e598a352d01fc22ec3367d9d84eec6c9add" integrity sha1-QpMuWYo1LQH8IuwzZ9nYTuxsmt0= -string-width@^1.0.1, string-width@^1.0.2: +string-width@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3" integrity sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M= @@ -10038,11 +10005,6 @@ whatwg-url@^7.0.0: tr46 "^1.0.1" webidl-conversions "^4.0.2" -which-module@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/which-module/-/which-module-1.0.0.tgz#bba63ca861948994ff307736089e3b96026c2a4f" - integrity sha1-u6Y8qGGUiZT/MHc2CJ47lgJsKk8= - which-module@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" @@ -10188,11 +10150,6 @@ xtend@^4.0.0, xtend@^4.0.1, xtend@~4.0.0, xtend@~4.0.1: resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54" integrity sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ== -y18n@^3.2.1: - version "3.2.1" - resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41" - integrity sha1-bRX7qITAhnnA136I53WegR4H+kE= - "y18n@^3.2.1 || ^4.0.0", y18n@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" @@ -10239,31 +10196,21 @@ yargs-parser@^15.0.0: camelcase "^5.0.0" decamelize "^1.2.0" -yargs-parser@^4.2.0: - version "4.2.1" - resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-4.2.1.tgz#29cceac0dc4f03c6c87b4a9f217dd18c9f74871c" - integrity sha1-KczqwNxPA8bIe0qfIX3RjJ90hxw= - dependencies: - camelcase "^3.0.0" - -yargs@6.6.0: - version "6.6.0" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-6.6.0.tgz#782ec21ef403345f830a808ca3d513af56065208" - integrity sha1-eC7CHvQDNF+DCoCMo9UTr1YGUgg= +yargs@13.3.0, yargs@^13.2.4: + version "13.3.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.3.0.tgz#4c657a55e07e5f2cf947f8a366567c04a0dedc83" + integrity sha512-2eehun/8ALW8TLoIl7MVaRUrg+yCnenu8B4kBlRxj3GJGDKU1Og7sMXPNm1BYyM1DOJmTZ4YeN/Nwxv+8XJsUA== dependencies: - camelcase "^3.0.0" - cliui "^3.2.0" - decamelize "^1.1.1" - get-caller-file "^1.0.1" - os-locale "^1.4.0" - read-pkg-up "^1.0.1" + cliui "^5.0.0" + find-up "^3.0.0" + get-caller-file "^2.0.1" require-directory "^2.1.1" - require-main-filename "^1.0.1" + require-main-filename "^2.0.0" set-blocking "^2.0.0" - string-width "^1.0.2" - which-module "^1.0.0" - y18n "^3.2.1" - yargs-parser "^4.2.0" + string-width "^3.0.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^13.1.1" yargs@^12.0.2: version "12.0.5" @@ -10283,22 +10230,6 @@ yargs@^12.0.2: y18n "^3.2.1 || ^4.0.0" yargs-parser "^11.1.1" -yargs@^13.2.4: - version "13.3.0" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-13.3.0.tgz#4c657a55e07e5f2cf947f8a366567c04a0dedc83" - integrity sha512-2eehun/8ALW8TLoIl7MVaRUrg+yCnenu8B4kBlRxj3GJGDKU1Og7sMXPNm1BYyM1DOJmTZ4YeN/Nwxv+8XJsUA== - dependencies: - cliui "^5.0.0" - find-up "^3.0.0" - get-caller-file "^2.0.1" - require-directory "^2.1.1" - require-main-filename "^2.0.0" - set-blocking "^2.0.0" - string-width "^3.0.0" - which-module "^2.0.0" - y18n "^4.0.0" - yargs-parser "^13.1.1" - yargs@^14.0.0, yargs@^14.2.2: version "14.2.2" resolved "https://registry.yarnpkg.com/yargs/-/yargs-14.2.2.tgz#2769564379009ff8597cdd38fba09da9b493c4b5"