Commit aea660d
authored
feat(tool): Respect user-data-dir flag from web-browser-flag (flutter#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.md1 parent c1c38ad commit aea660d
File tree
2 files changed
+51
-3
lines changed- packages/flutter_tools
- lib/src/web
- test/web.shard
2 files changed
+51
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
148 | 174 | | |
149 | 175 | | |
150 | 176 | | |
| |||
189 | 215 | | |
190 | 216 | | |
191 | 217 | | |
192 | | - | |
193 | | - | |
194 | | - | |
| 218 | + | |
195 | 219 | | |
196 | 220 | | |
197 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
931 | 931 | | |
932 | 932 | | |
933 | 933 | | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
934 | 958 | | |
935 | 959 | | |
936 | 960 | | |
| |||
0 commit comments