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
This commit is contained in:
JoelEinbinder 2017-08-21 20:12:16 -07:00 committed by Andrey Lushnikov
parent 1f9b4fb4c8
commit 11e3343b3d

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
const os = require('os');
const path = require('path'); const path = require('path');
const removeSync = require('rimraf').sync; const removeSync = require('rimraf').sync;
const childProcess = require('child_process'); const childProcess = require('child_process');
@ -20,12 +21,11 @@ const Downloader = require('../utils/ChromiumDownloader');
const Connection = require('./Connection'); const Connection = require('./Connection');
const Browser = require('./Browser'); const Browser = require('./Browser');
const readline = require('readline'); const readline = require('readline');
const crypto = require('crypto'); const fs = require('fs');
const helper = require('./helper'); const helper = require('./helper');
const ChromiumRevision = require('../package.json').puppeteer.chromium_revision; const ChromiumRevision = require('../package.json').puppeteer.chromium_revision;
const CHROME_PROFILE_PATH = path.resolve(__dirname, '..', '.dev_profile'); const CHROME_PROFILE_PATH = path.join(os.tmpdir(), 'puppeteer_dev_profile-');
let browserId = 0;
const DEFAULT_ARGS = [ const DEFAULT_ARGS = [
'--disable-background-networking', '--disable-background-networking',
@ -50,13 +50,9 @@ class Launcher {
* @param {!Object=} options * @param {!Object=} options
* @return {!Promise<!Browser>} * @return {!Promise<!Browser>}
*/ */
static async launch(options = {}) { static async launch(options) {
const userDataDir = [ options = options || {};
CHROME_PROFILE_PATH, const userDataDir = fs.mkdtempSync(CHROME_PROFILE_PATH);
process.pid,
++browserId,
crypto.randomBytes(8 / 2).toString('hex') // add random salt 8 characters long.
].join('-');
const chromeArguments = DEFAULT_ARGS.concat([ const chromeArguments = DEFAULT_ARGS.concat([
`--user-data-dir=${userDataDir}`, `--user-data-dir=${userDataDir}`,