aklinker1 / vite-plugin-web-extension

Vite plugin for developing Chrome/Web Extensions
https://vite-plugin-web-extension.aklinker1.io/
MIT License
653 stars 58 forks source link

Temporary folder is created both in /tmp and in my project's directory in WSL #220

Open paolostyle opened 1 week ago

paolostyle commented 1 week ago

Summary

It is probably caused by some extenral dependency that creates the temp files, but I'm reporting it here as I don't know what exactly is causing it.

When I run vite (or pnpm start in the repro repo below), generally everything works fine, but a new folder is created in the main project directory, named more or less \\wsl.localhost\Ubuntu-20.04\tmp\tmp-web-ext--26812-4hebg9Fx5Dr7 (notice the backslashes). Interestingly, a folder with exactly the same name is created in /tmp directory in the Linux file system.

If I remove it, nothing really breaks, the extension and hot reloading is working fine in the browser, but when I'm making changes it gets recreated. This is super annoying as this folder is not removed automatically when I close Vite and another one gets created after the restart. For now I gitignored it but it's really annoying and it shouldn't happen.

I'm quite certain this only happens on WSL so if you don't have it set up it's going to be difficult to reproduce. But I'm obviously willing to help out with debugging, just need some pointers on what might be causing it.

Reproduction

https://github.com/paolostyle/vite-web-ext-repro

Focus mostly on vite.config.ts, the rest I think is mostly irrelevant. Chrome runs from WSL so that might also potentially be the cause (?)

Environment

Likely critically important information that is not visible below - I'm running Ubuntu under WSL on Windows 11.

  System:
    OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 5800HS with Radeon Graphics
    Memory: 2.51 GB / 7.47 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v20.17.0/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
    pnpm: 9.12.3 - ~/.nvm/versions/node/v20.17.0/bin/pnpm
    bun: 1.1.29 - ~/.bun/bin/bun
  Browsers:
    Chrome: 131.0.6778.69
aklinker1 commented 4 days ago

What version of web-ext-run is installed?

paolostyle commented 3 days ago

0.2.2 it seems.

FWIW I found out that WXT exists and migrated to that, though in any case this should probably be fixed.

aklinker1 commented 3 days ago

Yeah, this should probably be moved to web-ext-run, but I don't have a windows machine so someone else will have to look into it :(

paolostyle commented 2 days ago

I spent some time debugging and it seems like it's not an issue with web-ext-run or even web-ext but rather with chrome-launcher. See this issue: https://github.com/GoogleChrome/chrome-launcher/issues/334. The workaround described there does solve the issue, so I can create a PR to web-ext-run if you'd be interested. This change makes a bunch of tests fail though so I'd have to look into it, or optionally we could just add this flag only when in WSL using something like is-wsl. On the other hand WXT makes me install the extension manually (perhaps we could try to solve it, at least partially?), so this would only be useful for this Vite plugin.

Overall ideally this issue would be fixed in chrome-launcher but I feel like this is going to be a huge rabbit hole. I won't even attempt to fix it upstream in web-ext because I don't think it supports WSL very well anyway and they probably just want to have it fixed in chrome-launcher.

Let me know what do you think about this.

As for the GH issue itself - agreed, if you can move this issue there (I'm not sure if it's possible but I think it is) that would be great.

aklinker1 commented 3 hours ago

On the other hand WXT makes me install the extension manually (perhaps we could try to solve it, at least partially?)

Oh yeah, after writing this plugin and seeing how many people were running into problems with WSL, I disabled auto-opening the browser in WXT. My recommendation would be to not use WSL with the plugin, use CMD/Powershell instead. There are more issues than just this one with WSL support, that's why I recommend not using it.

And I agree that this should be fixed in chrome-launcher.