Skip to content

Enable having chrome launches persist the window locations between runs #38537

Description

@devoncarew

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

Activity

  1. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    platform-webWeb applications specifically
    on Aug 14, 2019
  2. added this to the milestone on Aug 15, 2019
  3. jonahwilliams commented on Aug 29, 2019

    @jonahwilliams
    Contributor

    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

  4. devoncarew commented on Oct 15, 2019

    @devoncarew
    ContributorAuthor

    Hmm, this landed, but when trying out launching flutter web apps locally, the Chrome browser location isn't preserved.

  5. devoncarew commented on Oct 15, 2019

    @devoncarew
    ContributorAuthor

    I don't see a .dart_tool/chrome_profile/ directory for my project; was this change reverted?

  6. jonahwilliams commented on Oct 15, 2019

    @jonahwilliams
    Contributor

    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.

  7. devoncarew commented on Oct 15, 2019

    @devoncarew
    ContributorAuthor

    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.

  8. 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
  9. devoncarew commented on Oct 15, 2019

    @devoncarew
    ContributorAuthor

    I updated the title to re-focus this away from just solving the issue via the data dir.

  10. devoncarew commented on Oct 29, 2019

    @devoncarew
    ContributorAuthor

    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?

  11. jonahwilliams commented on Oct 29, 2019

    @jonahwilliams
    Contributor

    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.dart and then separately running flutter 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

  12. devoncarew commented on Oct 31, 2019

    @devoncarew
    ContributorAuthor

    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
  13. jonahwilliams commented on Nov 3, 2019

    @jonahwilliams
    Contributor

    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.

  14. github-actions commented on Aug 13, 2021

    @github-actions

    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 -v and a minimal reproduction of the issue.

  15. locked as resolved and limited conversation to collaborators on Aug 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

platform-webWeb applications specificallytoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions