mozilla / web-ext

A command line tool to help build, run, and test web extensions
Mozilla Public License 2.0
2.62k stars 334 forks source link

Running with a Windows .exe from WSL #2108

Open TheExGenesis opened 3 years ago

TheExGenesis commented 3 years ago

Is this a feature request or a bug?

Feature

What is the current behavior?

I'm using WSL to develop. I want to use a Windows firefox.exe. It only works if you pass it -profile as a Windows path, not as a Linux path.

    run: {
        target:['firefox-desktop'],
        firefox: '/mnt/c/Program Files/Mozilla Firefox/firefox.exe',
        profileCreateIfMissing: true,
    },

I set my TMPDIR to a Windows path, but it's interpreted as a relative path and the profile directory is appended in linux-style.

export TMPDIR='C:\Users\frsc\AppData\Roaming\Mozilla\Firefox\Profiles'

Error: ENOENT: no such file or directory, mkdir '/mnt/c/Users/frsc/Documents/Projects/th/appTh/localTsTh/C:\Users\frsc\AppData\Roaming\Mozilla\Firefox\Profiles/bbf19a52-6815-4788-84eb-3b8c6cf3874e'

What is the expected or desired behavior?

I'd like to be able to run web-ext with a windows .exe from WSL. It seems the only change needed is to pass profile as a Windows path rather than a linux path.

rpl commented 3 years ago

We have discussed about this in our triage meeting today and we are willing to review and merge changes that may make this use case possible and easier.

To make it easier to support this, we could introduce a special wsl mode, we could either introduce a new --wsl option to enable the special behaviors or try to detect it automatically (by detecting that web-ext is running under wsl and if the path to firefox is in a windows path).

I think that I may prefer an explicit --wsl as a first step, because it would be simpler and also less likely to regress behaviors when not running in wsl.

Whe the --wsl option is passed, web-ext will have to (at least):

I'm willing to mentor a contributor that may want to try to implement this strategy and create a pull request, and so I'm marking this issue as contrib:welcome (because this may be tricky enough to not make a great fit for a good first bug).

rpl commented 3 years ago

For reasons unrelated to this issue I've been using windows for a bit and I took that opportunity to look for reasonable implementation strategies for the issues we already know about (in particular path conversions) and to double-check if there may be other kind of issues that we will need to solve.

wslpath tool to convert paths between WSL2 and Windows formats

It looks that in WSL there is a binary named 'wslpath` which can be used to convert a WSL path into the related windows path and viceversa.

Apparently (I wasn't aware of that feature) a windows App can actually access a file from an arbitrary WSL2 path, but based on a quick experiment I did it seems that Firefox may have issues if the profile is in a WSL2 path and if that is actually the case we may still have to choose a temporary directory that would be directly accessible from an application running on the Windows side (but it was a quick test and so it would be good to double-check that explicitly when we are actually looking into the changes needed to fix this issue)

issues related to TCP connection between WSL2 and Windows applications

web-ext does need to be able to connect to the TCP port opened by Firefox for the RemoteDebuggingProtocol.

Under normal circumstances Firefox will listen on a TCP port only on localhost, and the TCP port to be used is provided by web-ext, which choose a port that is currently available, unfortunately this has two issues in the WSL2 scenario:

This issue would definitely require some more investigation, we should be able to force Firefox to do not listen only on localhost (by setting the devtools.debugger.force-local about:config preference to false), but that would be exposing the RDP port to more than just localhost and (given that we do have to also disable the "remote connection prompt") that concerns me a bit as a workaround, it would be nice to look for other ways to deal with it (if any other solution does actually exist).

NotChristianGarcia commented 3 years ago

New to the topic completely. But ran into this today on WSL2.

Would it be possible to manually configure the listening host? As it is, WSL2 development requires a lot of filling in configs with the current IP address acting as localhost (ip addr | grep eth0). So being able to provide said IP isn't too large of a problem. Having said IP picked up by web-ext and piped into the exe seems like an even more streamlined option if you were to pursue the --wsl flag, but an devtools config options seems pretty nifty.

fwenzel commented 2 years ago

Is there a workaround for this? It seems impossible to develop Firefox extensions on WSL2?

dot-mike commented 1 year ago

Can relate to this error. I get the following along with an error from Firefox it-self: Your Firefox profile cannot be loaded. It may be missing or inaccessible.

Running Firefox with WSL paths:

mike@mike-desktop:~/code/myproject$ export TMPDIR=/mnt/c/Users/mike/AppData/Local/Temp/
mike@mike-desktop:~/code/myproject$ npx web-ext run --verbose --source-dir ./src/ --firefox="/mnt/c/Program Files/Firefox Nightly/firefox.exe" -p "/mnt/c/Users/mike/AppData/Local/Mozilla/Firefox/Profiles/po9k4ydu.default-nightly"
[/home/mike/code/myproject/node_modules/web-ext/lib/program.js][info] Version: 7.4.0
[/home/mike/code/myproject/node_modules/web-ext/lib/program.js][debug] Discovering config files. Set --no-config-discovery to disable
[/home/mike/code/myproject/node_modules/web-ext/lib/config.js][debug] Discovered config "/home/mike/.web-ext-config.js" does not exist or is not readable
[/home/mike/code/myproject/node_modules/web-ext/lib/config.js][debug] Discovered config "/home/mike/code/myproject/web-ext-config.js" does not exist or is not readable
[/home/mike/code/myproject/node_modules/web-ext/lib/program.js][info] Applying config file: ./package.json
[/home/mike/code/myproject/node_modules/web-ext/lib/config.js][debug] Loading JS config file: "/home/mike/code/myproject/package.json" (resolved to "/home/mike/code/myproject/package.json")
[/home/mike/code/myproject/node_modules/web-ext/lib/config.js][debug] Looking for webExt key inside package.json file
[/home/mike/code/myproject/node_modules/web-ext/lib/config.js][debug] Config file /home/mike/code/myproject/package.json did not define any options. Did you set module.exports = {...}?
[/home/mike/code/myproject/node_modules/web-ext/lib/cmd/run.js][info] Running web extension from /home/mike/code/myproject/src
[/home/mike/code/myproject/node_modules/web-ext/lib/util/manifest.js][debug] Validating manifest at /home/mike/code/myproject/src/manifest.json
[/home/mike/code/myproject/node_modules/web-ext/lib/extension-runners/firefox-desktop.js][debug] Copying Firefox profile from /mnt/c/Users/mike/AppData/Local/Mozilla/Firefox/Profiles/po9k4ydu.default-nightly
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/index.js][debug] Copying profile directory from "/mnt/c/Users/mike/AppData/Local/Mozilla/Firefox/Profiles/po9k4ydu.default-nightly"
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/index.js][debug] Running Firefox with profile at /mnt/c/Users/mike/AppData/Local/Temp/firefox-profilexhaCIV/
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/index.js][debug] Executing Firefox binary: /mnt/c/Program Files/Firefox Nightly/firefox.exe
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/index.js][debug] Firefox args: -start-debugger-server 33995 -foreground -no-remote -profile /mnt/c/Users/mike/AppData/Local/Temp/firefox-profilexhaCIV/
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/index.js][info] Use --verbose or --devtools to see logging
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Connecting to the remote Firefox debugger
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Connecting to Firefox on port 33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/index.js][debug] Firefox stderr: Error: argument --profile requires a path
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Retrying Firefox (0); connection error: Error: connect ECONNREFUSED 127.0.0.1:33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Connecting to Firefox on port 33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Retrying Firefox (1); connection error: Error: connect ECONNREFUSED 127.0.0.1:33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Connecting to Firefox on port 33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/index.js][debug] Firefox stdout: [GFX1-]: shader-cache: Shader disk cache is not supported
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/index.js][debug] Firefox stderr: [2022-11-30T13:23:10Z ERROR webrender_bindings::program_cache] shader-cache: Shader disk cache is not supported
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Retrying Firefox (2); connection error: Error: connect ECONNREFUSED 127.0.0.1:33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Connecting to Firefox on port 33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Retrying Firefox (3); connection error: Error: connect ECONNREFUSED 127.0.0.1:33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Connecting to Firefox on port 33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Retrying Firefox (4); connection error: Error: connect ECONNREFUSED 127.0.0.1:33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Connecting to Firefox on port 33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Retrying Firefox (5); connection error: Error: connect ECONNREFUSED 127.0.0.1:33995
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/remote.js][debug] Connecting to Firefox on port 33995

Node.js v18.12.1

Running Firefox with WSL binary-path and Windows profile-path:

npx web-ext run --verbose --source-dir ./src/ --firefox="/mnt/c/Program Files/Firefox Nightly/firefox.exe" -p "C:\Users\mike\AppData\Local\Mozilla\Firefox\Profiles\po9k4ydu.default-nightly" --keep-profile-changes --devtools
[/home/mike/code/myproject/node_modules/web-ext/lib/program.js][info] Version: 7.4.0
[/home/mike/code/myproject/node_modules/web-ext/lib/program.js][debug] Discovering config files. Set --no-config-discovery to disable
[/home/mike/code/myproject/node_modules/web-ext/lib/config.js][debug] Discovered config "/home/mike/.web-ext-config.js" does not exist or is not readable
[/home/mike/code/myproject/node_modules/web-ext/lib/config.js][debug] Discovered config "/home/mike/code/myproject/web-ext-config.js" does not exist or is not readable
[/home/mike/code/myproject/node_modules/web-ext/lib/program.js][info] Applying config file: ./package.json
[/home/mike/code/myproject/node_modules/web-ext/lib/config.js][debug] Loading JS config file: "/home/mike/code/myproject/package.json" (resolved to "/home/mike/code/myproject/package.json")
[/home/mike/code/myproject/node_modules/web-ext/lib/config.js][debug] Looking for webExt key inside package.json file
[/home/mike/code/myproject/node_modules/web-ext/lib/config.js][debug] Config file /home/mike/code/myproject/package.json did not define any options. Did you set module.exports = {...}?
[/home/mike/code/myproject/node_modules/web-ext/lib/cmd/run.js][info] Running web extension from /home/mike/code/myproject/src
[/home/mike/code/myproject/node_modules/web-ext/lib/util/manifest.js][debug] Validating manifest at /home/mike/code/myproject/src/manifest.json
[/home/mike/code/myproject/node_modules/web-ext/lib/extension-runners/firefox-desktop.js][debug] Using Firefox profile from C:\Users\mike\AppData\Local\Mozilla\Firefox\Profiles\po9k4ydu.default-nightly
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/index.js][debug] profiles.ini not found: Error: ENOENT: no such file or directory, stat '/home/mike/.mozilla/firefox/profiles.ini'
[/home/mike/code/myproject/node_modules/web-ext/lib/firefox/index.js][debug] Assuming C:\Users\mike\AppData\Local\Mozilla\Firefox\Profiles\po9k4ydu.default-nightly is a named profile
/home/mike/code/myproject/node_modules/ini/ini.js:67
  const lines = str.split(/[\r\n]+/g)
                    ^

TypeError: Cannot read properties of undefined (reading 'split')
    at Object.decode (/home/mike/code/myproject/node_modules/ini/ini.js:67:21)
    at ReadFileContext.callback (/home/mike/code/myproject/node_modules/firefox-profile/lib/profile_finder.js:57:24)
    at FSReqCallback.readFileAfterOpen [as oncomplete] (node:fs:324:13)

Node.js v18.12.

EDIT: I had a typo in the WSL-path for Windows system-drive, it has to be lower case c.

EDIT 2: need to have proper Windows profilepath for Firefox, but it breaks ProfileFinder in web-ext...

bogdano2 commented 7 months ago

Could this be solved with wsplath from WSLU which is installed by default with the Ubuntu distribution?

WSL Utilities package provides ability to use the wslpath command.

Example usage:

cd $(wslpath 'C:\Users\Documents') ... will change to /mnt/c/Users//Documents.

The reverse conversion is also possible with the -w option:

mspaint.exe $(wslpath -w ~/profile.jpg) ... will open the file \wsl$\home\profile.jpg in the Paint application.

bogdano2 commented 7 months ago

For Windows/WSL environments, using a 'softlink' approach using the Windows buit-in 'mklink' command can also be combined by the developer to help this issue. This would require a documentation update targeted at WSL users and perhaps a targeted error message.

For example, the something along the following command should be helpful: mklink /d c:\mnt\c \\wsl$\\Ubuntu