Comments (8)
Yeah, currently not possible. I hadn't thought of that use-case.
How about this?
var close = opn('http://sindresorhus.com');
close();
Suggestions on a better API welcome.
from open.
I tried to implement it by replacing execFile
with spawn
; Then I was able to kill
the child process with signals (SIGINT
, SIGTERM
, …), but the actual application wasn’t terminated.
After a quick research, it looks like there’s no easy way to achieve this.
Leaving this open for further discussion.
from open.
I've been toying with the same issue. How about allowing the user to provide a options hash with { wait: false }
to override the default behaviour of waiting if opn
is called with a callback?
In that case it should just call the callback once the child processes returns from opening the URL.
I can make a pull request if you'd like
from open.
@watson 👍 Sounds like a better behaviour than the current way :)
from open.
@sindresorhus Currently the api for the opn
function is: opn(target, [app], [callback])
. I think it would be too complicated to both understand and implement if we added an options hash between the app
and the callback
argument.
But since the app
argument is seldom used, couldn't we then just make that part of the options hash? I.e. opn(target, [options], [callback])
, where options have the following optional properties:
{
app: "...", // default is platform dependent
wait: false // default is true if a callback is also given
}
from open.
That would of cause be a breaking change, which I would rather not introduce... but we could of cause detect if it was given a string and fall back to the old behaviour - or just bump the major version? Let me know what you think
from open.
opn(target, [options], [callback])
looks good to me.
I'm fine with breaking backwards compat in a major as I doubt the app
feature is used much.
from open.
@sindresorhus ^ here you go - let me know what you think :)
from open.
Related Issues (20)
- error - uncaughtException: Error: spawn undefined\System32\WindowsPowerShell\v1.0\powershell ENOENT HOT 1
- Running open module inside Ubuntu on wsl2 always opens browser in windows
- A question HOT 1
- Issue: Windows not opening browser or any client application without `wait: true` or setting a long timeout HOT 2
- Error: spawn UNKNOWN at ChildProcess.spawn (node:internal/child_process:412:11) at Object.spawn (node:child_process:698:9) at module.exports (C:\Users\{username}\Downloads\{react-project-name}\node_modules\better-opn\node_modules\open\index.js:175:34) { errno: -4094, code: 'UNKNOWN', syscall: 'spawn' }
- It doesn't fall back to other binaries when `wait: false`
- esm support HOT 2
- this seems to switch execution context on Windows to Powershell when using "cmd"
- Make powershell EncodedCommand optional HOT 1
- Not using a default export HOT 1
- Can I open a .docx file and automatically search or scroll to the specific text? HOT 1
- how to use it in Vite + Vue3? HOT 1
- how to check chrome is installed
- Release v9.1.1 (Nodejs v20 fix) HOT 2
- Library doesn't seem to work when importing dynamically? HOT 2
- How to open a link with open browers' F12 developer tools?
- Argument list quotes aren't escaped for PowerShell
- ``wait: true`` doesn't work using Firefox
- Can't open `mailto:[email protected]` in browser
- Cannot find name 'ChildProcess' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from open.