Repository navigation
Enable having chrome launches persist the window locations between runs #38537
Description
Activity
- addedtoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.platform-webWeb applications specificallyWeb applications specifically
on Aug 14, 2019 I'm going to start with using the .dart_tool directory, since it is already gitignored and can be removed automatically on clean. If that isn't sufficient we can also explore configuration the location via flutter config
Hmm, this landed, but when trying out launching flutter web apps locally, the Chrome browser location isn't preserved.
I don't see a
.dart_tool/chrome_profile/directory for my project; was this change reverted?Sorry - yes, this was reverted because it prevents multiple instances of chrome from running. If there are two instances of chrome sharing a profile the second will silently fail to launch. That includes any background processes it seems, so it led to some weird to debug issues.
Gotcha. It would be great to figure out a way to have the window position persist between sessions (at least for most launches?). When testing out flutter web launches, it is annoying to get your windows positioned well (IntelliJ and Chrome), and then have them reset on each run.
- changed the title
[-]Create a persistent user-data-dir for the chrome launched for web devices[/-][+]Enable having chrome launches persist the window locations between runs[/+]on Oct 15, 2019 I updated the title to re-focus this away from just solving the issue via the data dir.
To ping this issue - I think we should find a way to solve this. Having to re-position your chrome window each time you run the app is annoying.
If there are two instances of chrome sharing a profile the second will silently fail to launch
What we do on other 'devices' is to close any currently running app before we start a new one. What do you think about that for a solution - allowing only one running copy of the Chrome+user-data-dir combo at a time (and killing any already running one)?
Can you describe a bit more how people would get into the situation of starting up an app in the same project when there was already a running one?
I think the reason we were seeing the issue more frequently is that we were failing to properly cleanup chrome when it was closed via the window/tab controls. This would leave a phantom instance floating around that would cause the second run to fail to start up.
More generally, there is nothing wrong with
flutter run -d chrome --target=lib/main_a.dartand then separately runningflutter run -d chrome --target=lib/main_b.dart. We could use a lock or similar to prevent the second from running but that seems user hostile.Perhaps we could do something like, start chrome using the temp directory. But that temp directory could be both populated from a known location, and then copied back to that location on close
Perhaps we could do something like, start chrome using the temp directory. But that temp directory could be both populated from a known location, and then copied back to that location on close
That sounds like a good idea. It does mean we don't have to be in the business of terminating Chrome processes.
flutter run -d chrome --target=lib/main_a.dart
For this to work - to allow running multiple apps from the same project - we could make the path to the user data dir also incorporate some portion of the target app's entrypoint script. I think I like the copying idea above better however.
Another idea is that if we know a chrome process is running for the current project directory, we could connect to it and open the 2nd launch in a new chrome tab (or a new chrome window but in the same process). That might have the best UX, but would involve some additional logging into the app's .dart_tool directory that we don't currently do. Something like:
- log the chrome debug port each time we run an app
- when running an app, see if info about a chrome debug port exists in the .dart_tool dir, and if so, see if we can connect via the chrome debug protocol
I looked into this a bit and there is a single file that controls preferences like window size. I had good luck with copying it around - this seems like a reasonably simple way to start.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Aug 13, 2021
We currently create a temporary directory to hold Chrome's user-data-dir each time we launch a web device:
https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/web/chrome.dart#L81
This means that the position of the chrome window won't be remembered between sessions.
The user will position it, but when they next launch their app, will need to reposition it.
We may instead want to write the the --user-data-dir to the .dart_tool/ dir in the project, or a persistent dir in their home directory?
cc @jonahwilliams