From 3a5e1d69ab6aed340876ffa296420c866783decd Mon Sep 17 00:00:00 2001 From: Alan Knight Date: Mon, 21 Oct 2019 16:28:55 -0700 Subject: [PATCH 1/3] Allow passing in a user-data-dir --- lib/src/chrome.dart | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/src/chrome.dart b/lib/src/chrome.dart index ea1a144..2a8b3de 100644 --- a/lib/src/chrome.dart +++ b/lib/src/chrome.dart @@ -41,18 +41,16 @@ String get _executable { /// Manager for an instance of Chrome. class Chrome { - Chrome._( - this.debugPort, - this.chromeConnection, { - Process process, - Directory dataDir, - }) : _process = process, + Chrome._(this.debugPort, this.chromeConnection, + {Process process, Directory dataDir, this.deleteDataDir = false}) + : _process = process, _dataDir = dataDir; final int debugPort; final ChromeConnection chromeConnection; final Process _process; final Directory _dataDir; + final bool deleteDataDir; /// Connects to an instance of Chrome with an open debug port. static Future fromExisting(int port) async => @@ -61,12 +59,14 @@ class Chrome { /// Starts Chrome with the given arguments and a specific port. /// /// Each url in [urls] will be loaded in a separate tab. - static Future startWithDebugPort( - List urls, { - int debugPort, - bool headless = false, - }) async { - final dataDir = Directory.systemTemp.createTempSync(); + static Future startWithDebugPort(List urls, + {int debugPort, bool headless = false, String userDataDir}) async { + Directory dataDir; + if (userDataDir == null) { + dataDir = Directory.systemTemp.createTempSync(); + } else { + dataDir = Directory(userDataDir); + } final port = debugPort == null || debugPort == 0 ? await findUnusedPort() : debugPort; @@ -108,6 +108,7 @@ class Chrome { ChromeConnection('localhost', port), process: process, dataDir: dataDir, + deleteDataDir: userDataDir = null, )); } @@ -150,8 +151,10 @@ class Chrome { // Chrome starts another process as soon as it dies that modifies the // profile information. Give it some time before attempting to delete // the directory. - await Future.delayed(Duration(milliseconds: 500)); - await _dataDir?.delete(recursive: true); + if (deleteDataDir) { + await Future.delayed(Duration(milliseconds: 500)); + await _dataDir?.delete(recursive: true); + } } catch (_) { // Silently fail if we can't clean up the profile information. // It is a system tmp directory so it should get cleaned up eventually. From a3f2454206255775c1146769f034589dfb16e783 Mon Sep 17 00:00:00 2001 From: Alan Knight Date: Mon, 21 Oct 2019 16:42:07 -0700 Subject: [PATCH 2/3] Add a CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7922d36..43a2732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 0.1.4 - Start Chrome maximized. +- Add a parameter to use a specified user-data-dir instead of a system temp. ## 0.1.3 From 72aae6f9e0d132fa967aa7d01e8b6d1ff4064284 Mon Sep 17 00:00:00 2001 From: Alan Knight Date: Mon, 21 Oct 2019 16:43:44 -0700 Subject: [PATCH 3/3] CHANGELOG and pubspec correctly for 0.1.5 --- CHANGELOG.md | 5 ++++- pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43a2732..4a1b460 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ +## 0.1.5 + +- Add a parameter to use a specified user-data-dir instead of a system temp. + ## 0.1.4 - Start Chrome maximized. -- Add a parameter to use a specified user-data-dir instead of a system temp. ## 0.1.3 diff --git a/pubspec.yaml b/pubspec.yaml index 9a3ffc6..59c3d46 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: browser_launcher description: Provides a standardized way to launch web browsers for testing and tools. -version: 0.1.4 +version: 0.1.5 author: Dart Team homepage: https://github.com/dart-lang/browser_launcher