From 11e3343b3d8c5a0cca4cb6abc08c749e71c23233 Mon Sep 17 00:00:00 2001 From: JoelEinbinder Date: Mon, 21 Aug 2017 20:12:16 -0700 Subject: [PATCH] Put chrome profiles into a temporary directory (#439) This patch: - puts chrome profiles into a temporary directory - starts using `fs.mkdtemp` to create temp profile directories --- lib/Launcher.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/Launcher.js b/lib/Launcher.js index 1b2bc042..d76a5baf 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +const os = require('os'); const path = require('path'); const removeSync = require('rimraf').sync; const childProcess = require('child_process'); @@ -20,12 +21,11 @@ const Downloader = require('../utils/ChromiumDownloader'); const Connection = require('./Connection'); const Browser = require('./Browser'); const readline = require('readline'); -const crypto = require('crypto'); +const fs = require('fs'); const helper = require('./helper'); const ChromiumRevision = require('../package.json').puppeteer.chromium_revision; -const CHROME_PROFILE_PATH = path.resolve(__dirname, '..', '.dev_profile'); -let browserId = 0; +const CHROME_PROFILE_PATH = path.join(os.tmpdir(), 'puppeteer_dev_profile-'); const DEFAULT_ARGS = [ '--disable-background-networking', @@ -50,13 +50,9 @@ class Launcher { * @param {!Object=} options * @return {!Promise} */ - static async launch(options = {}) { - const userDataDir = [ - CHROME_PROFILE_PATH, - process.pid, - ++browserId, - crypto.randomBytes(8 / 2).toString('hex') // add random salt 8 characters long. - ].join('-'); + static async launch(options) { + options = options || {}; + const userDataDir = fs.mkdtempSync(CHROME_PROFILE_PATH); const chromeArguments = DEFAULT_ARGS.concat([ `--user-data-dir=${userDataDir}`,