web-ext icon indicating copy to clipboard operation
web-ext copied to clipboard

Running with a Windows .exe from WSL

Open TheExGenesis opened this issue 4 years ago • 7 comments

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.

TheExGenesis avatar Jan 05 '21 19:01 TheExGenesis

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):

  • choose a temporary dir for the temporary profile directory in a path that will be accessible to the Firefox instance running as a regular windows app
  • build the extension sources as an xpi (similarly to what we do when web-ext run is used to run an extension on an android device) and put the xpi in a temporary directory accessible to the windows application (and/or maybe optionally not build the extension into an xpi if the source dir is in a path that would already be accessible)
  • translate the paths to the extension and to the Firefox profile into a path that the windows app would be able to access (e.g. translating /mnt/c/somedir into C:\mnt\c\somedir)

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 avatar Jan 13 '21 17:01 rpl

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:

  • by default Firefox will listen on localhost, but localhost from inside WSL2 isn't the same localhost visible from outside of WSL2 (WSL2 does use a VM-approach to contain the linux system, whereas WSL1 was using a "container"-like approach) and so web-ext will not be able to reach the windows' Firefox TCP port without further changes

  • web-ext will choose a port that is free inside WSL2, but that port may not be actually being used outside of WSL2 by some other windows application

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).

rpl avatar Feb 08 '21 18:02 rpl

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.

NotChristianGarcia avatar Mar 06 '21 01:03 NotChristianGarcia

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

fwenzel avatar Oct 23 '21 22:10 fwenzel

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...

dot-mike avatar Nov 30 '22 13:11 dot-mike

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 avatar Dec 03 '23 18:12 bogdano2

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

bogdano2 avatar Dec 03 '23 20:12 bogdano2