wxt icon indicating copy to clipboard operation
wxt copied to clipboard

Persist data not working (Windows11, Chrome)

Open placoderm opened this issue 1 year ago • 16 comments

Describe the bug

I'm reading through the new docs and am trying to implement persist-data

I have this in my web-ext.config.ts file (which is in my root):

// web-ext.config.ts
export default defineRunnerConfig({
  chromiumArgs: ["--user-data-dir=./.wxt/chrome-data"],
});

I saved, restarted VSCode and ran pmpm dev. There was no new directory added to .wxt for /chrome-data/

I installed a plugin in the dev launched Chrome, cancelled the dev, restarted everything, and the plugin was not there.

Please see the discussion on https://discord.com/channels/1212416027611365476/1290064175791472670

This problem seems to be exclusive to Windows.

Reproduction

I also tried:

// wxt.config.ts
export default defineConfig({
  runner: { chromiumArgs: ["--user-data-dir=./.wxt/chrome-data"] },
});

Still with no success.

Steps to reproduce

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 2.78 GB / 15.33 GB
  Binaries:
    Node: 18.17.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.4.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.11.0 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
    Chrome: Version 129.0.6668.71 (Official Build) (64-bit)
  npmPackages:
    wxt: ^0.19.1 => 0.19.10

Used Package Manager

pnpm

Validations

placoderm avatar Oct 01 '24 19:10 placoderm

Thanks for the report. If anyone has windows and can try to reproduce this, I'd appreciate this. It works on Linux and Mac.

aklinker1 avatar Oct 02 '24 14:10 aklinker1

I should also emphasize that I may be doing something completely wrong on my end. Would be wonderful if another Windows user could test.

placoderm avatar Oct 02 '24 17:10 placoderm

Greetings I can conform that this is the case as well on my windows computer

Judimax avatar Oct 02 '24 19:10 Judimax

@Judimax Can you try and launch Chrome directly and mess around with the CLI flags to see if you can find something that stores chrome data in a different directory?

chrome.exe --user-data-dir=chrome-data

aklinker1 avatar Oct 02 '24 23:10 aklinker1

im in the discord if you want to hop on a call to debug?

Judimax avatar Oct 02 '24 23:10 Judimax

@placoderm @Judimax _kdme_ that windows user, has posted something like this before, which may help to solve something.

  • https://discord.com/channels/1212416027611365476/1268068051874742312/1268499442831724676
  • https://discord.com/channels/1212416027611365476/1270035277087248457/1270648007800520705

1natsu172 avatar Oct 03 '24 07:10 1natsu172

Greetings this seems to only work for Profile 1 any other profile I get, and Profile 1 seems to be a dummy profile of sorts ERROR connect ECONNREFUSED 127.0.0.1:58396 6:45:35 a.m.

at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16)

Judimax avatar Oct 03 '24 10:10 Judimax

im in the discord if you want to hop on a call to debug?

@Judimax Sorry, was checking in on things before I went to bed.

That said, I forgot that I had a windows VM on my work computer, so I played around. First try got it working:

chrome.exe --user-data-dir="C:\\Users\Username\Downloads\chrome-data"

And it worked just fine. C:\\Users\Username\Downloads\chrome-data did NOT exist beforehand, chrome created it when it started up.

Also tried with a relative path, as shown in the example:

"C:\Program Files\Google\Chrome\Application\chrome.exe" --user-data-dir=".\.wxt\chrome-data"

But this doesn't work. It shows an alert when starting up that "Google Chrome cannot read and write to its data directory: ..wxt\chrome-data"

Same error with and without the leading ".". Also throws the error if I create the .wxt directory and the .wxt/chrome-data directory.

However, it does work if I use an absolute path:

"C:\Program Files\Google\Chrome\Application\chrome.exe" --user-data-dir="C:\Users\Username\Downloads\test\.wxt\chrome-data"

So it appears the only requirement is you use an absolute path. And I put it in quotes just to be safe.


That means this should work for windows users:

// web-ext.config.ts
import { resolve } from 'node:path';

export default defineRunnerConfig({
  chromiumArgs: [`--user-data-dir="${resolve(".wxt/chrome-data")}"`
});

I will update the docs

aklinker1 avatar Oct 03 '24 16:10 aklinker1

  chromiumArgs: [`--user-data-dir="${resolve(".wxt/chrome-data")}"`],

So that didn't work for me. Here is my `web-ext.config.ts:

import { defineRunnerConfig } from "wxt";
import { resolve } from "node:path";

export default defineRunnerConfig({
  chromiumArgs: [`--user-data-dir="${resolve(".wxt/chrome-data")}"`],
});

When I run that the profile that chrome uses is still here:

C:\Users\...\AppData\Local\Temp\tmp-web-ext--13824-DkSV2bod0aOw\Default

I try adding bookmarks to the bookmark bar and starting again. When I restart they are gone.

placoderm avatar Oct 03 '24 20:10 placoderm

@placoderm can you try quitting chrome completely from the task manager before running the command?

Also, try running Chrome directly:

"C:\Program Files\Google\Chrome\Application\chrome.exe" --user-data-dir="C:\Users\Username\Downloads\test\.wxt\chrome-data"

aklinker1 avatar Oct 03 '24 23:10 aklinker1

When I run in chrome directly as you suggest it works, creating a new profile. Running again, it goes to that same profile.

I tried quitting chrome from taskmanager and running with

  chromiumArgs: [`--user-data-dir="${resolve(".wxt/chrome-data")}"`],

in web-ext.config.ts. Still didn't work.

I copied the chrome-data the commandline created in the downloads folder to the .wxt folder in my project. Still didn't use that.

placoderm avatar Oct 03 '24 23:10 placoderm

I copied the chrome-data the commandline created in the downloads folder to the .wxt folder in my project. Still didn't use that.

Wait, hold on, so it did create a chrome-data folder at some point?

aklinker1 avatar Oct 03 '24 23:10 aklinker1

Wait, hold on, so it did create a chrome-data folder at some point?

Yes, when I did this on the command line:

"C:\Program Files\Google\Chrome\Application\chrome.exe" --user-data-dir="C:\Users\Username\Downloads\test\.wxt\chrome-data"

As expected it created a new profile and launched chrome. Sorry that wasn't more clear.

placoderm avatar Oct 03 '24 23:10 placoderm

OK, can you run wxt --debug and share the output? Make sure to keep

chromiumArgs: [`--user-data-dir="${resolve(".wxt/chrome-data")}"`],

in your config file. You can ctrl+C out of the command once the browser opens.

Specifically, there should be a section at the very bottom containing the web-ext config, that's all I care about. Will look something like this:

⚙ web-ext config: { console: undefined,                                                                    7:12:35 PM
  devtools: undefined,
  startUrl: [ 'https://duckduckgo.com' ],
  keepProfileChanges: undefined,
  chromiumBinary: undefined,
  chromiumProfile: undefined,
  chromiumPref: { devtools: { synced_preferences_sync_disabled: [Object] } },
  args: undefined,
  target: 'chromium',
  sourceDir:
   '/home/aklinker1/Development/github.com/wxt-dev/wxt/packages/wxt-demo/.output/chrome-mv3',
  noReloadManagerExtension: true,
  noReload: true,
  noInput: true }
⚙ web-ext options: { shouldExitProgram: false }

aklinker1 avatar Oct 04 '24 00:10 aklinker1

Here you go…

⚙ web-ext config: { console: undefined,                                               1:26:41 PM
  devtools: undefined,
  startUrl:
   [ 'https://suttacentral.net',
     'https://suttacentral.net/mn82/en/sujato',
     'https://discourse.suttacentral.net/t/mn25-absent-from-bh-bodhis-classes/36183' ],
  keepProfileChanges: undefined,
  chromiumBinary: undefined,
  chromiumProfile: undefined,
  chromiumPref: { devtools: { synced_preferences_sync_disabled: [Object] } },
  args:
   [ '--user-data-dir="C:\\Users\\learn\\Videos\\PROJECTS\\SC-plugin-parts\\SuttaCentral-Enhancement-Extension\\.wxt\\chrome-data"' ],
  target: 'chromium',
  sourceDir:
   'C:\\Users\\learn\\Videos\\PROJECTS\\SC-plugin-parts\\SuttaCentral-Enhancement-Extension\\.output\\chrome-mv3',
  noReloadManagerExtension: true,
  noReload: true,
  noInput: true }
⚙ web-ext options: { shouldExitProgram: false }                                       1:26:41 PM   
✔ Opened browser in 795 ms                                                            1:26:41 PM   

And here is my exact web-ext.config.ts:

import { defineRunnerConfig } from "wxt";
import { resolve } from "node:path";

export default defineRunnerConfig({
  startUrls: ["https://suttacentral.net", "https://suttacentral.net/mn82/en/sujato", "https://discourse.suttacentral.net/t/mn25-absent-from-bh-bodhis-classes/36183"],
  chromiumArgs: [`--user-data-dir="${resolve(".wxt/chrome-data")}"`],
});

placoderm avatar Oct 04 '24 00:10 placoderm

Huh, alright yeah, no idea why it doesn't work for you. That all looks good. It's clearly using an absolute path, and WXT is properly passing the arguments through to web-ext.

aklinker1 avatar Oct 04 '24 12:10 aklinker1

I will post on Discord and see if there is a windows user there who can test.

placoderm avatar Oct 04 '24 17:10 placoderm

@aklinker1 Why don't you pass the example zip you are testing to @placoderm ? You two are not working on the same reproduction, right? Just to be safe, the less difference the better for debug.

1natsu172 avatar Oct 04 '24 18:10 1natsu172

userDataDir is not retrived from chromeFlags.

chromium.js in module web-ext-run:

  let {
    userDataDir,
    profileDirName
  } = await ChromiumExtensionRunner.getProfilePaths(this.params.chromiumProfile);

......

  this.chromiumInstance = await this.chromiumLaunch({
    enableExtensions: true,
    chromePath: chromiumBinary,
    chromeFlags,
    startingUrl,
    userDataDir,
    // Ignore default flags to keep the extension enabled.
    ignoreDefaultFlags: true,
    prefs: this.getPrefs(),
    port
  });

So this works, but it requires that the specified directory already exists, as it will not be created automatically like the temporary directory.

  runner: {
    ...
    chromiumProfile: "./.wxt/chrome-data",
    ...
  },

breadgrocery avatar Oct 17 '24 04:10 breadgrocery

I had a similar problem with configuring persistence in Google Chrome on Windows 11. What the docs are saying currently seems to be totally irrelevant. I can also confirm that what works for me is this (in web-ext.config.ts file):

import { resolve } from 'node:path';
import { defineRunnerConfig } from 'wxt';

export default defineRunnerConfig({
    // I'm not even sure if path resolving is required on W11
    chromiumProfile: `${resolve('.wxt/chrome-data')}`,
});

Only chromiumProfile needs to be set as the target directory for configs. That's it. Nothing else is requried. Hope it helps anybody :)

Either the docs need to be updated or the browser runner needs some changes. At this point, documentation is very misleading on this one and indeed confuses newbies.

szymski avatar Nov 01 '24 20:11 szymski

So... Should I just update the docs to use chromiumProfile instead of --user-data-dir? Does just using a profile keep you logged into sites from previous sessions?

On mac, I know it doesn't work like that. Since it copies files into a temp dir, logins don't persist, and you have to log in every time. That's why --user-data-dir works, it doesn't move or copy the files, so you stay logged in.

Do we also need to recommend using keepProfileChanges alongside chromiumProfile?

export default defineRunnerConfig({
    chromiumProfile: `${resolve('.wxt/chrome-data')}`,
    keepProfileChanges: true,
});

If so, I think it makes sense to create option that automatically applies the required config based on the current operating system.

export default defineRunnerConfig({
    preset: "persist"
    // Windows:
    // chromiumProfile: `${resolve('.wxt/chrome-data')}`,
    // keepProfileChanges: true,
    // Mac/Linux:
    // chromiumArgs: ["--user-data-dir=./.wxt/chrome-data"],
});

aklinker1 avatar Nov 14 '24 08:11 aklinker1

I can confirm this combination works on Windows 11:

export default defineRunnerConfig({
    chromiumProfile: `${resolve('.wxt/chrome-data')}`,
    keepProfileChanges: true,
});

You need keepProfileChanges set to true otherwise the profile is new everytime chrome is started.

kmanev073 avatar Nov 21 '24 22:11 kmanev073

Alright, I've updated the docs. Gonna close this now that we've found a solution.

aklinker1 avatar Nov 22 '24 14:11 aklinker1

Thanks for all your hard work!

placoderm avatar Nov 22 '24 17:11 placoderm