Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I cann't understand. Use powershell in wsl to open the default? #270

Open
bigbigDreamer opened this issue Dec 8, 2021 · 2 comments
Open

Comments

@bigbigDreamer
Copy link

open/index.js

Line 123 in 7579417

} else if (platform === 'win32' || (isWsl && !isDocker())) {

command = isWsl ?
   `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe` :
   `${process.env.SYSTEMROOT}\\System32\\WindowsPowerShell\\v1.0\\powershell`;

Now I modified the source file in node modules and used xdg-open can work normal.

Delete || (isWsl && !isDocker()), because wsl also is linux plateform.

But, Note: You should give your current wsl system login user root privileges.

#269

@bigbigDreamer
Copy link
Author

In particular, you can install xdg-open in your wsl in advance.

$ sudo apt-get update 

$ sudo apt-get install xdg-open

Then, xdg-open can automatically open the default browser on your host machine, provided that you have sufficient permissions.

you can try edit the source code in open from node_modules:

if (app) {
	command = app;
} else {
	// When bundled by Webpack, there's no actual package file path and no local `xdg-open`.
	const isBundled = !__dirname || __dirname === '/';

	// Check if local `xdg-open` exists and is executable.
	let exeLocalXdgOpen = false;
	try {
			await fs.access(localXdgOpenPath, fsConstants.X_OK);
			exeLocalXdgOpen = true;
	} catch {}

		// const useSystemXdgOpen = process.versions.electron ||
		// 	platform === 'android' || isBundled || !exeLocalXdgOpen;
		// command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath;
		command =  'xdg-open';
}

Finally,u can use as follow:

const open = require('open');

open(url, { wait: true })

Don't add app param!

@mklueh
Copy link

mklueh commented Apr 24, 2022

In my case, I have given WSL restricted access to the host machine intentionally to work as a sandbox. It still tries to access Powershell. What should I do?

byCedric added a commit to expo/expo that referenced this issue Jul 4, 2023
…rs on Windows (#23287)

# Why

Fixes #23252

# How

- `open` has a bug on Windows, where it [uses
`process.env.SYSTEMROOT`](https://github.com/sindresorhus/open/blob/main/index.js#L173)
instead of
[`process.env.SystemRoot`](https://en.wikipedia.org/wiki/Environment_variable#:~:text=The%20%25SystemRoot%25%20variable%20is%20a,including%20the%20drive%20and%20path.)
- This causes the executed command to run with `undefined\\...`
- There has been no fix yet, and due to `open` being fully ESM now, we
probably can't upgrade too

> See various issues
[#300](sindresorhus/open#300),
[#292](sindresorhus/open#292),
[#270](sindresorhus/open#270), or
[#205](sindresorhus/open#205)

This basically sets the missing `SYSTEMROOT` when trying to open a
browser on Windows. It's fixed in both `@expo/cli` as well as
`@expo/dev-server` (to open the Chrome DevTools).

# Test Plan

This has to be tested on Windows.

- `$ yarn create expo ./test-browser -t tabs@beta`
- `$ cd ./test-browser`
- `$ yarn start`
- Try pressing the following keys:
- `j` -> to open the Chrome DevTools, after connecting a device. Should
work as expected.
  - `w` -> to open the browser with Metro web. Should work as expected.

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
byCedric added a commit to expo/expo that referenced this issue Jul 4, 2023
…rs on Windows (#23287)

# Why

Fixes #23252

# How

- `open` has a bug on Windows, where it [uses
`process.env.SYSTEMROOT`](https://github.com/sindresorhus/open/blob/main/index.js#L173)
instead of
[`process.env.SystemRoot`](https://en.wikipedia.org/wiki/Environment_variable#:~:text=The%20%25SystemRoot%25%20variable%20is%20a,including%20the%20drive%20and%20path.)
- This causes the executed command to run with `undefined\\...`
- There has been no fix yet, and due to `open` being fully ESM now, we
probably can't upgrade too

> See various issues
[#300](sindresorhus/open#300),
[#292](sindresorhus/open#292),
[#270](sindresorhus/open#270), or
[#205](sindresorhus/open#205)

This basically sets the missing `SYSTEMROOT` when trying to open a
browser on Windows. It's fixed in both `@expo/cli` as well as
`@expo/dev-server` (to open the Chrome DevTools).

# Test Plan

This has to be tested on Windows.

- `$ yarn create expo ./test-browser -t tabs@beta`
- `$ cd ./test-browser`
- `$ yarn start`
- Try pressing the following keys:
- `j` -> to open the Chrome DevTools, after connecting a device. Should
work as expected.
  - `w` -> to open the browser with Metro web. Should work as expected.

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [ ] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants