check out my latest app: Icon Preview
and my latest blog post
Open stuff like URLs, files, executables. Cross-platform.
License: MIT License
check out my latest app: Icon Preview
and my latest blog post
I'm building a simple debugging tool for the awesome Node API framework Lux, which uses node --inspect
. Node's new built in inspector spits back a chrome-devtools://
url, which I'd like to open automatically.
However, opn doesn't seem to respect chrome-devtools
URLs, even when I pass Google Chrome explicitly as the application to open. I'm therefore resorting to using a MacOSx-only solution of opening the URL using an osascript
.
Is there an easy fix for whitelisting chrome-devtools
URLs?
I'm trying to use opn to open a URL. The script is running in a shell process on a remote Ubuntu server. Since there's no GUI, no browser opens, which makes sense. But I can't tell if it worked or not, since the return value of opn is undefined either way, and the callback doesn't get called either way.
Another solution might be to attempt to open lynx...
Following code works fine - opens the exact URL in chrome.
var open = require("opn");
open('http://codef0rmer.github.io/eShell/index.html#/1?name=foobar', {app: 'chrome'});
However, if Chrome is a default browser and it's not mentioned then both hash and querystrings are stripped.
var open = require("opn");
open('http://codef0rmer.github.io/eShell/index.html#/1?name=foobar');
Any idea why spawn
strips querystring?
I haven't really looked into index.js for this problem, but this doesn't occur on all urls. This only occurs when I have a space in the url I am trying to open.
To reproduce this issue on windows 10, do opn('https://www.google.com/#q=12 3&*', {app: 'Chrome'})
and the url in the browser will be https://www.google.com/#q=12 3^&*
, however, if I do opn('https://www.google.com/#q=123&*', {app: 'Chrome'})
the url opened in the browser is not modified.
I noticed there is a regex replacement target.replace(/&/g, '^&')
in index.js, but im not sure why it doesn't replace all the &s with ^&
if exists a chrome instance , opn will open a tag on this chrome instance
i want to open a new instance
I would like to use opn in my package.json.
E.g. "start": "npm run open & ecstatic . --defaultExt htm"
my application is hosted on digital ocean server.
so my question is: can i open a browser from access the app url or api url in my local system.
please reply me.
because i hosted my app and when i trying to open a url from api link, its not opening any browser in my local system where i access this url.
On Windows, this is passing '""'
as the first argument to start
to avoid start
interpreting a quoted filename as the title of a console window. As it turns out, this seems to be automatically escaped just like the filename itself: if I run opn("cmd")
, I get a cmd window with the title \\
(I guess the quotes disappear but the attempt to escape them does not), whereas if I change '""'
to just ''
or ""
I get a cmd window with no title as expected. This does not appear to affect running any actual file/url one way or the other (opn("some file")
still works right), so it doesn't really matter as far as functionality, but I wanted to point it out as far as theoretical correctness goes. File under "fun fact" I guess.
(It also seems that instead of a blank window title, an actual window title could be given; but I'm not sure that's useful, between the fact that there are better ways to open a console from Node and the fact that a blank window title would be odd but not confusing whereas any name hardcoded in opn
could be irrelevant in whatever hypothetical usage did cause cmd
to be opened through opn
.)
Please see DavidAnson/vscode-markdownlint#4 for more details.
Briefly, the workflow for publishing a VS Code extension from Windows and running it on Linux does not preserve the execute
bit for the xdg-open
script, so opn
fails when called on Linux.
@jdumas proposes a change to opn
in the above issue that may help (but I don't have the platform expertise to say for sure).
It could be nice if "opn" package support Zeit "pkg" :) .
Currently, building a cross-platform packages with "pkg" don't work well with "opn", it do nothing and browser don't open :
Error: spawn /snapshot/deploy/node_modules/opn/xdg-open ENOENT
I will try some solution and update the issue, but i think "pkg" doesn't work with bash script (xdg-open is not packaged).
If MS Edge is closed by the time opn is invoked, running this script results in only the first URL being loaded:
const opn = require('opn');
const urlList = ['https://github.com/sindresorhus/opn', 'https://www.google.com'];
urlList.map(opn); // assuming Edge is the system default browser
If another browser is used (e.g. firefox) it works as expected (i.e. it opens multiple instances of the browser if it's closed, or it opens multiple tabs inside the same browser instance if there is one available - this is true for Edge too).
Is there any functionality for saving opened page?
var gulp = require('gulp');
var opn = require('opn');
var _open = function () {
opn('http://sindresorhus.com', {app: 'firefox'});
}
gulp.task('open', function () {
_open();
});
~
[email protected] /home/one/github/torq-ui
└── [email protected]
[12:45:55] Starting 'open'...
[12:45:55] 'open' errored after 1.47 ms
[12:45:55] TypeError: Bad argument
at ChildProcess.spawn (child_process.js:936:24)
at Object.exports.spawn (child_process.js:736:9)
at module.exports (/home/one/github/torq-ui/node_modules/opn/index.js:58:24)
at _open (/home/one/github/torq-ui/gulp/tasks/open.js:5:5)
at Gulp.<anonymous> (/home/one/github/torq-ui/gulp/tasks/open.js:9:5)
at module.exports (/home/one/github/torq-ui/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
at Gulp.Orchestrator._runTask (/home/one/github/torq-ui/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
at Gulp.Orchestrator._runStep (/home/one/github/torq-ui/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
at Gulp.Orchestrator.start (/home/one/github/torq-ui/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
at /usr/lib64/node_modules/gulp/bin/gulp.js:129:20
at process._tickCallback (node.js:419:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:906:3
Use-case: #4
Something like: opn('http://todomvc.com', ['chrome', '--incognito']);
System: Linux (Ubuntu 14.04)
opn version: 5.1.0
xdg-open version: 1.1.2
File path with query param doesn't work:
$ ~/node_modules/opn/xdg-open /some/path/index.html?hi
xdg-open: file '/usr/local/google/home/chenwilliam/lighthouse/plots/charts/index.html?hi' does not exist
File path without query param works as expected and opens page in Chrome:
$ ~/node_modules/opn/xdg-open /some/path/index.html
Created new window in existing browser session.
Regular URL path with query param works:
https://www.paulirish.com/?hi
Seems related to this issue? https://bugs.freedesktop.org/show_bug.cgi?id=45857
I have tried to open iTerm and run a command inside, but it fails. Here is the snippet:
opn('ls', { app: '/Applications/iTerm 2.app' });
It tries to open the file named ls
.
Hi Team,
Can someone push a example of using the promise that contain child process. I want to get the handle to child process and kill the process after certain period of time..
E.g
opn(imagePath,{wait : true}).then((cProcess) => {
console.log("closed");
cProcess.on('exit', (code) => {
console.log(Child exited with code ${code}
);
});
setTimeout(function(cProcess) { /* do something with this after 3000 */} , 3000);
});
I see the app can be specified with {app: 'name'}
How do I know or look up what the app name need to be to correspond to a particular program?
I want to open a url with Chrome Canary instead of my default browser (Chrome) but I've tried various names without it working. This is on Windows but is there a OS generic way to check the app names?
How to open website in the older existed browser tab, not new tab
Reproduce by opening chrome and then calling opn('http://google.com/', function() { console.log('closed'); });
The callback is immediately called and chrome remains open.
@sindresorhus you recently helped me debug where opn wasn't working in Electron.
It would be nice if opn
could handle Electron seamlessly. Any interest in a PR adding support for it?
Specifically:
shell.open*
method(node:16) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Exited with code 3
I apparently get this error when I open links using the module in Docker container. I tested the code in my local before I put the code on my server which uses Docker. And It literally works well in my local that doesn't use Docker. So I assume that something is wrong with docker but there's actually no way to figure out what the problem is. Is there anyone who has ever used 'opn' module with Docker?
Additionally, after I set node version of my server to the same as my local one, It doesn't says the promise error but still doesn't open any links.
Hello,
Thanks to your job I'm able to open an application (an Excel file in my case).
Do you know something to close this Excel application after some processing that I need to do ?
Thank you,
Mathieu
Installing the package with npm i opn -S
(or directly from git repo) does not preserve executable attribute on xdg-open
, resulting in EACCESS
when opn-ing URLs.
app.get('/url', function (req, res) {
try {
opn('http://google.com/', {app: 'firefox'});
} catch (e) {
console.log(e);
}
});
I have used this code in my nodejs file.
this code works perfectly in localhost but not working on hosting server.
when i access "domain.com/url" then it give me error and firefox not open at all.
The errors are like this:
0|my-api | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
0|my-api | Error: spawn firefox ENOENT
0|my-api | at exports._errnoException (util.js:1020:11)
0|my-api | at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
0|my-api | at onErrorNT (internal/child_process.js:367:16)
0|my-api | at _combinedTickCallback (internal/process/next_tick.js:80:11)
0|my-api | at process._tickDomainCallback (internal/process/next_tick.js:128:9)
Please help me to access the url and open browser that mentioned in parameters.
i have hosted this app on digitalocean.
what should i do to run the code perfectly and open browser.
I need following functionality:
url
is opened in Browser - ist should be only activated.currently there is no option to have the promise fulfill when the browser has been opened. Only either when the browser has been exited or immediately after execution by setting wait to false.
Is there a way to figure out when it has been successfully opened so i can activate a macro when its happened ?
Hi,
I am using this module with Grunt to display errors in the browser
while coding. However, the focus (on the editor) is lost after opening the browser, which is not very handy.
It would be nice if there could be an option to disable this behavior, but I am not sure
how it could be implemented cross-platform. For OS X, passing -g
to the open
command
should be ok, but I cannot find any equivalent for xdg-open
.
Any ideas?
Hi @sindresorhus,
it seems like there’s currently no way to quit opened apps, since opn
doesn’t return anything and the callback
function gets executed once the corresponding app was terminated. Am I missing something?
The incorrect default app is opened by xdg-open (1.0.2) when providing an url.
The system provided xdg-open (1.1.0 rc3) opens the correct default app.
Could it be possible to check if xdg-open exists before using xdg-open provided by the package?
Updating xdg-open to at least 1.1.0-rc1 also opens the correct app.
I was just wondering if this was possible. Some people on our team use Atom, others Sublime, and I'd like to use opn to open the project directory (root folder, i.e. '.') in the user's default IDE.
Is there a way to open a website and exit the terminal without killing the browser?
Hello,
I see in 5.0.0 that arrow functions were introduced. This unfortunately made the module incompatible with the Chromium Embedded Framework version I have to use for my product.
I'd understand if ES6 compatibility is required going forward, but it'd be great to keep using whatever improvements you introduce without needing to keep my own local edits or being stuck on an old version. As such, I'd ask that you reconsider.
Thank you!
In for es2015ifying this module and dropping all the dependencies? Or just a little bit too early?
Hi,
Can I open a new tab instead of opening a new window?
Best.
On windows when you run opn it opens a new .cmd every time you call it. It would be really nice if there was an option to hide those.
This works
opn('H:\command.bat');
but this just opens a command prompt without executing the the target bat file.
opn('H:\command.bat', {app: 'cmd'});
Tested on windows 10
(node:43) Error: Exited with code 3
at ChildProcess.cp.once.code (/frontend/node_modules/opn/index.js:82:13)
at Object.onceWrapper (events.js:318:30)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at maybeClose (internal/child_process.js:921:16)
at Socket.stream.socket.on (internal/child_process.js:348:11)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at Pipe._handle.close [as _onclose] (net.js:549:12)
at emitWarning (internal/process/promises.js:69:15)
at emitPendingUnhandledRejections (internal/process/promises.js:86:11)
at runMicrotasksCallback (internal/process/next_tick.js:124:9)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
(node:43) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
On newer versions of node, I receive this message.
After I open an URL in a new tab, I need to wait until the tab has been closed in order to execute some operations. It seems that opn
cannot detect it and you need to kill the whole browser processes in order to continue the code execution (supposing that {wait: true}
has been used).
Tried with Chrome and Firefox, same result. It's probably hard to detect the pid
of the opened tab as the browser (at least Chrome in this case) seems to create a new child process for the tab, which is not detected by opn
.
I'm wondering if there is any workaround for this.
I am a novice, I do not know why it has been guaranteed wrong, it is troubled, and for a long time did not fix it, I hope you can help me, thank you very much.
const opn = require('opn');
opn(' http://sindresorhus.com ');
Following your example for spawning an incognito session in Chrome doesn't appear to work anymore.
opn('http://sindresorhus.com', {app: ['google chrome', '--incognito']});
The above command, from your readme, opens the window in Chrome, but not in incognito mode.
OSX: 10.12.2
Chrome: 56.0.2924.87
require('opn')('http://httpbin.org/get?wan=one&tu=two&tree=three');
expected url: http://httpbin.org/get?wan=one&tu=two&tree=three
actual url: http://httpbin.org/get?wan=one
platform: windows
😏
Is it possible to open application with out file ? like outlook or cmd or putty, these application don't require file to open it (not like photoshop or MS word)
and what is the code to do that?
I caught some very strange behaviour and could not think of any possibility on how to solve it.
In grunt-contrib-connect v0.8, I used "google-chrome --incognito" to develop in incognito mode.
Now that opn
has been introduced in v0.9, chrome is not launched with this flag.
If I use simply google-chrome
or firefox
, it works perfectly.
I logged the cmd
variable before execFile and it seems OK.
Any ideas?
I've been using a shell script for opening internet shortcut and longed to port it to node.
I'm think of integrating the feature to opn
, what do you think?
Hi, I'd like to use this library in react for a dashboard I'm building for my company. The problem is that I cannot seem to get this to work in React using ES6 syntax. Is there any way I can get this to work? Or if not, could you recommend any alternatives?
For some reason, the process never exits when opening something, even without the callback. See https://github.com/kevva/github-search-repos/blob/master/cli.js#L51 for an example.
Happens with 0.10, 0.12 as well as io.js 1.6.4 on Ubuntu (running inside a VM). It doesn't seem to happen in Windows though.
opn data:,Hello%2C%20World!
should open the data URI in the browser but does nothing (OS X)
I tried your library in ubuntu
what could be the error :
var openurl = require('opn');
openurl("http://url.com");
It gives error as :
spawn EACCES: Error: spawn EACCES
at exports._errnoException (util.js:1022:11)
at ChildProcess.spawn (internal/child_process.js:313:11)
at Object.exports.spawn (child_process.js:399:9)
at module.exports (/home/lekhnath/.vscode/extensions/Shan.code-settings-sync-2.8.0/node_modules/opn/index.js:74:26)
at Commons.<anonymous> (/home/lekhnath/.vscode/extensions/Shan.code-settings-sync-2.8.0/out/src/commons.js:189:25)
at Generator.next (<anonymous>)
at fulfilled (/home/lekhnath/.vscode/extensions/Shan.code-settings-sync-2.8.0/out/src/commons.js:4:58)
e.onUnexpectedError @ workbench.main.js:29
(anonymous) @ workbench.main.js:29
e.onUnexpectedError @ workbench.main.js:28
o @ workbench.main.js:28
t.onUnexpectedExtHostError @ workbench.main.js:28
e.handle @ workbench.main.js:28
s @ workbench.main.js:28
f @ workbench.main.js:28
_combinedTickCallback @ internal/process/next_tick.js:67
_tickCallback @ internal/process/next_tick.js:98
I faced this error :
Error: Exited with code 3
at ChildProcess.cp.once.code (/etc/nginx/node_modules/opn/index.js:82:13)
at ChildProcess.g (events.js:292:16)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:891:16)
at Socket. (internal/child_process.js:342:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:497:12)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.