-
Notifications
You must be signed in to change notification settings - Fork 29.7k
feat(tools): Arbitrary browser flags (closes #65575) #104935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tools): Arbitrary browser flags (closes #65575) #104935
Conversation
|
@jonahwilliams kindly asking for a review, if you have time? |
jonahwilliams
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what that errors is caused by exactly, but could be related to a webdriver version mismatch. I would make sure your webdriver version is newer.
Does run work with this new flag?
I checked, Chromedriver version matches the Chrome version :/
Same error for Also tried it on my Linux-PC, same error message for both commands. Do I miss something? Btw: it recognizes when I use a wrong a wrong option, so the new source code seems to be valid somehow. Edit: I think I have to upgrade flutter to the |
You should be testing your tool changes with the version of the Dart SDK in your Flutter commit. If you use the bin/flutter bash or bin/flutter.bat batch wrapper scripts, this will ensure you are using the correct version of Dart to compile and run the tool: https://github.com/flutter/flutter/blob/master/bin/flutter |
Thanks worked now flawlessly: |
|
Kindly remind you for continuing the review |
jonahwilliams
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Looks like flutter drive already has web-browser-flags? Can you de-duplicate that? |
|
@christopherfujino @jonahwilliams can you have a look again? |
Can you rebase upstream? I'm sure you didn't break the goldens with this change, but a) it could be obscuring other legitimate failures, and b) we can't merge this without green pre-submits anyway. |
christopherfujino
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than failing pre-submits (likely not related), LGTM
45e6343 to
f0e41dc
Compare
|
@christopherfujino ok weird, the CI didn't like the merged, but rather rebased commits... |
|
@Gustl22 How can we use these chrome flags in |
|
I think like every other arg, too, by escaping the double quotes: {
...
"args": [
"--flavor",
"development",
"--web-browser-flag",
"\"--disable-web-security\""
]
}or {
...
"args": [
"--flavor=development",
"--web-browser-flag=\"--disable-web-security\""
]
}Let me know, if it's working. |
|
@Gustl22 yes it worked :) Also, would this flag work in release version of our web apps as well? When I use |
No this is just for development and testing. Or more specifically the user (client) can decide if they want to disable this security "feature". To make this working in production you have to enable CORS on your server. |
|
Thank you for the cool feature! This works: flutter run -d chrome --web-browser-flag "--disable-web-security" However, this doesn't work (user data dir setting is not applied): flutter run -d chrome --web-browser-flag "--user-data-dir=c:\tmp\somedir" Any thoughts? |
You may need to quote the path itself, too: flutter run -d chrome --web-browser-flag "--user-data-dir=\"c:\tmp\somedir\""
# or
flutter run -d chrome --web-browser-flag=--user-data-dir="c:\tmp\somedir" |
|
Nope :( The error message: You can see that there are two --user-data-dir params and it seems the first is taken into account by chrome :( |
|
The correct solution seems to be moving |
### Respect user-data-dir flag from web-browser-flag Currently, it's already possible to pass `web-browser-flag` when launching Chrome, but the `user-data-dir` flag doesn't work as expected, and there are some reasons for that. In the implementation made in [PR #104935](#104935), the `web-browser-flag` is appended at the end of the Chrome launch arguments. For most scenarios, this works fine, as demonstrated in the Chrome unit test below: https://source.chromium.org/chromium/chromium/src/+/main:base/command_line_unittest.cc ``` TEST(CommandLineTest, MultipleSameSwitch) { const CommandLine::CharType* argv[] = { FILE_PATH_LITERAL("program"), FILE_PATH_LITERAL("--foo=one"), // --foo first time FILE_PATH_LITERAL("-baz"), FILE_PATH_LITERAL("--foo=two") // --foo second time }; CommandLine cl(std::size(argv), argv); EXPECT_TRUE(cl.HasSwitch("foo")); EXPECT_TRUE(cl.HasSwitch("baz")); EXPECT_EQ("two", cl.GetSwitchValueASCII("foo")); } ``` In this scenario, the parser will consider the last occurrence of a flag. However, this behavior does not apply to certain flags, because Chrome processes some of them based on the first occurrence, not the last. This is the case for `--user-data-dir`, which is parsed very early during Chrome startup. The proposed code checks whether `--user-data-dir` was provided via `web-browser-flag`, and if so, it uses that value instead of the default `%temp%\flutter_tools_chrome_device.xpto` temporary directory. This also resolve this comment: #104935 (comment) Example: `launch.json` ``` { "version": "0.2.0", "configurations": [ { "name": "flutter", "request": "launch", "type": "dart" }, { "name": "flutter (profile mode)", "request": "launch", "type": "dart", "flutterMode": "profile" }, { "name": "flutter (release mode)", "request": "launch", "type": "dart", "flutterMode": "release" }, { "name": "Flutter for web (hot reloadable)", "type": "dart", "request": "launch", "program": "lib/main.dart", "args": [ "-d", "chrome", "--web-port=5000", "--web-experimental-hot-reload", "--web-browser-flag=--user-data-dir=D:\\_Desenv\\flutter_tests\\chrome_profile" ] } ] } ``` `chrome://version` | Before | After | |--------|--------| |  |  | Folder | Before | After | |--------|--------| |  |  | ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…#169445) ### Respect user-data-dir flag from web-browser-flag Currently, it's already possible to pass `web-browser-flag` when launching Chrome, but the `user-data-dir` flag doesn't work as expected, and there are some reasons for that. In the implementation made in [PR flutter#104935](flutter#104935), the `web-browser-flag` is appended at the end of the Chrome launch arguments. For most scenarios, this works fine, as demonstrated in the Chrome unit test below: https://source.chromium.org/chromium/chromium/src/+/main:base/command_line_unittest.cc ``` TEST(CommandLineTest, MultipleSameSwitch) { const CommandLine::CharType* argv[] = { FILE_PATH_LITERAL("program"), FILE_PATH_LITERAL("--foo=one"), // --foo first time FILE_PATH_LITERAL("-baz"), FILE_PATH_LITERAL("--foo=two") // --foo second time }; CommandLine cl(std::size(argv), argv); EXPECT_TRUE(cl.HasSwitch("foo")); EXPECT_TRUE(cl.HasSwitch("baz")); EXPECT_EQ("two", cl.GetSwitchValueASCII("foo")); } ``` In this scenario, the parser will consider the last occurrence of a flag. However, this behavior does not apply to certain flags, because Chrome processes some of them based on the first occurrence, not the last. This is the case for `--user-data-dir`, which is parsed very early during Chrome startup. The proposed code checks whether `--user-data-dir` was provided via `web-browser-flag`, and if so, it uses that value instead of the default `%temp%\flutter_tools_chrome_device.xpto` temporary directory. This also resolve this comment: flutter#104935 (comment) Example: `launch.json` ``` { "version": "0.2.0", "configurations": [ { "name": "flutter", "request": "launch", "type": "dart" }, { "name": "flutter (profile mode)", "request": "launch", "type": "dart", "flutterMode": "profile" }, { "name": "flutter (release mode)", "request": "launch", "type": "dart", "flutterMode": "release" }, { "name": "Flutter for web (hot reloadable)", "type": "dart", "request": "launch", "program": "lib/main.dart", "args": [ "-d", "chrome", "--web-port=5000", "--web-experimental-hot-reload", "--web-browser-flag=--user-data-dir=D:\\_Desenv\\flutter_tests\\chrome_profile" ] } ] } ``` `chrome://version` | Before | After | |--------|--------| |  |  | Folder | Before | After | |--------|--------| |  |  | ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…#169445) ### Respect user-data-dir flag from web-browser-flag Currently, it's already possible to pass `web-browser-flag` when launching Chrome, but the `user-data-dir` flag doesn't work as expected, and there are some reasons for that. In the implementation made in [PR flutter#104935](flutter#104935), the `web-browser-flag` is appended at the end of the Chrome launch arguments. For most scenarios, this works fine, as demonstrated in the Chrome unit test below: https://source.chromium.org/chromium/chromium/src/+/main:base/command_line_unittest.cc ``` TEST(CommandLineTest, MultipleSameSwitch) { const CommandLine::CharType* argv[] = { FILE_PATH_LITERAL("program"), FILE_PATH_LITERAL("--foo=one"), // --foo first time FILE_PATH_LITERAL("-baz"), FILE_PATH_LITERAL("--foo=two") // --foo second time }; CommandLine cl(std::size(argv), argv); EXPECT_TRUE(cl.HasSwitch("foo")); EXPECT_TRUE(cl.HasSwitch("baz")); EXPECT_EQ("two", cl.GetSwitchValueASCII("foo")); } ``` In this scenario, the parser will consider the last occurrence of a flag. However, this behavior does not apply to certain flags, because Chrome processes some of them based on the first occurrence, not the last. This is the case for `--user-data-dir`, which is parsed very early during Chrome startup. The proposed code checks whether `--user-data-dir` was provided via `web-browser-flag`, and if so, it uses that value instead of the default `%temp%\flutter_tools_chrome_device.xpto` temporary directory. This also resolve this comment: flutter#104935 (comment) Example: `launch.json` ``` { "version": "0.2.0", "configurations": [ { "name": "flutter", "request": "launch", "type": "dart" }, { "name": "flutter (profile mode)", "request": "launch", "type": "dart", "flutterMode": "profile" }, { "name": "flutter (release mode)", "request": "launch", "type": "dart", "flutterMode": "release" }, { "name": "Flutter for web (hot reloadable)", "type": "dart", "request": "launch", "program": "lib/main.dart", "args": [ "-d", "chrome", "--web-port=5000", "--web-experimental-hot-reload", "--web-browser-flag=--user-data-dir=D:\\_Desenv\\flutter_tests\\chrome_profile" ] } ] } ``` `chrome://version` | Before | After | |--------|--------| |  |  | Folder | Before | After | |--------|--------| |  |  | ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…#169445) ### Respect user-data-dir flag from web-browser-flag Currently, it's already possible to pass `web-browser-flag` when launching Chrome, but the `user-data-dir` flag doesn't work as expected, and there are some reasons for that. In the implementation made in [PR flutter#104935](flutter#104935), the `web-browser-flag` is appended at the end of the Chrome launch arguments. For most scenarios, this works fine, as demonstrated in the Chrome unit test below: https://source.chromium.org/chromium/chromium/src/+/main:base/command_line_unittest.cc ``` TEST(CommandLineTest, MultipleSameSwitch) { const CommandLine::CharType* argv[] = { FILE_PATH_LITERAL("program"), FILE_PATH_LITERAL("--foo=one"), // --foo first time FILE_PATH_LITERAL("-baz"), FILE_PATH_LITERAL("--foo=two") // --foo second time }; CommandLine cl(std::size(argv), argv); EXPECT_TRUE(cl.HasSwitch("foo")); EXPECT_TRUE(cl.HasSwitch("baz")); EXPECT_EQ("two", cl.GetSwitchValueASCII("foo")); } ``` In this scenario, the parser will consider the last occurrence of a flag. However, this behavior does not apply to certain flags, because Chrome processes some of them based on the first occurrence, not the last. This is the case for `--user-data-dir`, which is parsed very early during Chrome startup. The proposed code checks whether `--user-data-dir` was provided via `web-browser-flag`, and if so, it uses that value instead of the default `%temp%\flutter_tools_chrome_device.xpto` temporary directory. This also resolve this comment: flutter#104935 (comment) Example: `launch.json` ``` { "version": "0.2.0", "configurations": [ { "name": "flutter", "request": "launch", "type": "dart" }, { "name": "flutter (profile mode)", "request": "launch", "type": "dart", "flutterMode": "profile" }, { "name": "flutter (release mode)", "request": "launch", "type": "dart", "flutterMode": "release" }, { "name": "Flutter for web (hot reloadable)", "type": "dart", "request": "launch", "program": "lib/main.dart", "args": [ "-d", "chrome", "--web-port=5000", "--web-experimental-hot-reload", "--web-browser-flag=--user-data-dir=D:\\_Desenv\\flutter_tests\\chrome_profile" ] } ] } ``` `chrome://version` | Before | After | |--------|--------| |  |  | Folder | Before | After | |--------|--------| |  |  | ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…#169445) ### Respect user-data-dir flag from web-browser-flag Currently, it's already possible to pass `web-browser-flag` when launching Chrome, but the `user-data-dir` flag doesn't work as expected, and there are some reasons for that. In the implementation made in [PR flutter#104935](flutter#104935), the `web-browser-flag` is appended at the end of the Chrome launch arguments. For most scenarios, this works fine, as demonstrated in the Chrome unit test below: https://source.chromium.org/chromium/chromium/src/+/main:base/command_line_unittest.cc ``` TEST(CommandLineTest, MultipleSameSwitch) { const CommandLine::CharType* argv[] = { FILE_PATH_LITERAL("program"), FILE_PATH_LITERAL("--foo=one"), // --foo first time FILE_PATH_LITERAL("-baz"), FILE_PATH_LITERAL("--foo=two") // --foo second time }; CommandLine cl(std::size(argv), argv); EXPECT_TRUE(cl.HasSwitch("foo")); EXPECT_TRUE(cl.HasSwitch("baz")); EXPECT_EQ("two", cl.GetSwitchValueASCII("foo")); } ``` In this scenario, the parser will consider the last occurrence of a flag. However, this behavior does not apply to certain flags, because Chrome processes some of them based on the first occurrence, not the last. This is the case for `--user-data-dir`, which is parsed very early during Chrome startup. The proposed code checks whether `--user-data-dir` was provided via `web-browser-flag`, and if so, it uses that value instead of the default `%temp%\flutter_tools_chrome_device.xpto` temporary directory. This also resolve this comment: flutter#104935 (comment) Example: `launch.json` ``` { "version": "0.2.0", "configurations": [ { "name": "flutter", "request": "launch", "type": "dart" }, { "name": "flutter (profile mode)", "request": "launch", "type": "dart", "flutterMode": "profile" }, { "name": "flutter (release mode)", "request": "launch", "type": "dart", "flutterMode": "release" }, { "name": "Flutter for web (hot reloadable)", "type": "dart", "request": "launch", "program": "lib/main.dart", "args": [ "-d", "chrome", "--web-port=5000", "--web-experimental-hot-reload", "--web-browser-flag=--user-data-dir=D:\\_Desenv\\flutter_tests\\chrome_profile" ] } ] } ``` `chrome://version` | Before | After | |--------|--------| |  |  | Folder | Before | After | |--------|--------| |  |  | ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
…#169445) ### Respect user-data-dir flag from web-browser-flag Currently, it's already possible to pass `web-browser-flag` when launching Chrome, but the `user-data-dir` flag doesn't work as expected, and there are some reasons for that. In the implementation made in [PR flutter#104935](flutter#104935), the `web-browser-flag` is appended at the end of the Chrome launch arguments. For most scenarios, this works fine, as demonstrated in the Chrome unit test below: https://source.chromium.org/chromium/chromium/src/+/main:base/command_line_unittest.cc ``` TEST(CommandLineTest, MultipleSameSwitch) { const CommandLine::CharType* argv[] = { FILE_PATH_LITERAL("program"), FILE_PATH_LITERAL("--foo=one"), // --foo first time FILE_PATH_LITERAL("-baz"), FILE_PATH_LITERAL("--foo=two") // --foo second time }; CommandLine cl(std::size(argv), argv); EXPECT_TRUE(cl.HasSwitch("foo")); EXPECT_TRUE(cl.HasSwitch("baz")); EXPECT_EQ("two", cl.GetSwitchValueASCII("foo")); } ``` In this scenario, the parser will consider the last occurrence of a flag. However, this behavior does not apply to certain flags, because Chrome processes some of them based on the first occurrence, not the last. This is the case for `--user-data-dir`, which is parsed very early during Chrome startup. The proposed code checks whether `--user-data-dir` was provided via `web-browser-flag`, and if so, it uses that value instead of the default `%temp%\flutter_tools_chrome_device.xpto` temporary directory. This also resolve this comment: flutter#104935 (comment) Example: `launch.json` ``` { "version": "0.2.0", "configurations": [ { "name": "flutter", "request": "launch", "type": "dart" }, { "name": "flutter (profile mode)", "request": "launch", "type": "dart", "flutterMode": "profile" }, { "name": "flutter (release mode)", "request": "launch", "type": "dart", "flutterMode": "release" }, { "name": "Flutter for web (hot reloadable)", "type": "dart", "request": "launch", "program": "lib/main.dart", "args": [ "-d", "chrome", "--web-port=5000", "--web-experimental-hot-reload", "--web-browser-flag=--user-data-dir=D:\\_Desenv\\flutter_tests\\chrome_profile" ] } ] } ``` `chrome://version` | Before | After | |--------|--------| |  |  | Folder | Before | After | |--------|--------| |  |  | ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

Description
Ability to set arbitrary browser flags.
Example usage:
Related issues
#65575
Change policies
If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
I think there's no docs that need a migration guide, but we should adapt the WIKI
Notes
I could not test my changes in real use case as I get this error (on Windows Powershell):
Do you have a clue, how to execute the flutter tool command from source?
The unit tests seem to work fine.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.