michaellzc / better-opn Goto Github PK
View Code? Open in Web Editor NEWA better open. Reuse the same tab on Chromium-based browsers on macOS.
Home Page: https://www.npmjs.com/package/better-opn
License: MIT License
A better open. Reuse the same tab on Chromium-based browsers on macOS.
Home Page: https://www.npmjs.com/package/better-opn
License: MIT License
https://github.com/ExiaSR/better-opn/blob/c5d60ea88ba1f000f3bbc8fbbc0e97be239bb47b/src/index.js#L29
I hope I can not refresh the current tab page, tks~
Current implement of better-opn
passes the entire url to openChrome.applescript
to match an opened tab.
In some cases, when we debugging a web application, we navigate between urls and finally stay on another url that does not match the one passed to applescript.
This can especially happen when we set a specified url with some long pathname to better-opn
, in our case it is host.com/login
to ensure developers signed in first, but after that the url becomes host.com/some-module
and cannot be matched against host.com/login
.
We'd like to see an option to "loosely determine which tab to reuse" by passing only host.com
to applescript.
now no type file or @types/better-opn. and typescript report error
Projects with Storybook set up (which it seems uses better-opn
) fail to start for me, unless I override BROWSER
for the command. For a dozen years or more mine has been set to x-www-browser:www-browser
.
I forget what prompted me to set it that way originally, and it's a bit hard to find documentation of exactly what BROWSER
is supposed to be. After a bit of digging I found this Stackoverflow question which asks where the docs are, and one of the answers says
The
BROWSER
variable is not in the same league asEDITOR
orPAGER
- it is not mentioned by the standards. However, some programs may use them, likeman
:
man 1 man
(Debian):BROWSER If $BROWSER is set, its value is a colon-delimited list of com- mands, each of which in turn is used to try to start a web browser for man --html. In each command, %s is replaced by a filename containing the HTML output from groff, %% is replaced by a single percent sign (%), and %c is replaced by a colon (:).
Right now when it's set with a colon-separated list, better-opn
fails:
node:events:368
throw er; // Unhandled 'error' event
^
Error: spawn x-www-browser:www-browser ENOENT
at Process.ChildProcess._handle.onexit (node:internal/child_process:282:19)
at onErrorNT (node:internal/child_process:477:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (node:internal/child_process:288:12)
at onErrorNT (node:internal/child_process:477:16)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn x-www-browser:www-browser',
path: 'x-www-browser:www-browser',
spawnargs: [ 'http://localhost:6006/' ]
}
because I don't have anything called x-www-browser:www-browser
.
To follow the way man
uses the variable better-opn
would try each of the commands in turn. If that's overkill, just splitting by colon then running the first one would be an improvement.
Hey, thanks for creating this package, looks good!
Would you be amenable to opening an issue / pull request in the open
package (renamed from the original name opn
) to add these features to upstream?
I searched for issues or PRs opened under your name in the project but didn't find anything yet.
Since this package is widely used (by Storybook, Gatsby, and others) and it's not easy to find docs on how it is supposed to be configured (via the BROWSER
environment variable, I believe), I would suggest that this package checks user OS preferences first before defaulting to something like:
const shouldTryOpenChromiumWithAppleScript =
process.platform === 'darwin' &&
(typeof browser !== 'string' || browser === OSX_CHROME);
(https://github.com/michaellzc/better-opn/blob/master/src/index.js#L53)
(For me personally, it was non-straightforward that Gatsby always opened my dev build in Chrome even though it's not my default browser, even if that allowed some advanced behaviour like re-using the same tab).
We can detect the default browser through a package like x-default-browser, and if it is indeed one of the supported Chromium browsers, then it should, of course utilise its advanced capabilities.
Any thoughts on that? Happy to send in a PR to add OS preferences checking and do the necessary work to ensure backward compatibility if you're okay with this change.
Hey, i meet a bug, use this url will open two tabs in chrome.
opn('https://github.com?range=1&result=2')
I guess it is because i used '&'
Hello,
I recently installed Windows ARM64 on a parallels VM to check compatibility of the devops chain we use.
One issue I found is that the browser window does not open. I am using better-opn.
Hence, this issue report.
Thank you for this great package.
Hi,
I came across an issue with running storybook which is dependant on this npm.
The issue lies in my IT restricting powershell...
I would apreciate some help letting me know how to set a diffrent shell for the use (the command arg in the image attached).
Please see attachment for more details
node:internal/errors:464
ErrorCaptureStackTrace(err);
^
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\akoenig\WORKSPACE\storybook-angular-testing-master\node_modules\better-opn\node_modules\open\index.js:175:34) {
errno: -4094,
code: 'UNKNOWN',
syscall: 'spawn'
}
P.s.
I tried setting the defaut shell for npm but this had no effect...if anyone knows which config to edit and how so the command will path to another shell I would really appreciate the help.
Edit:
I tried to manually tweak the code but this failed,I lack the knowledge to make this work right
Ever since Storybook changed to use better-opn
my default browser doesn't open anymore when I run it, but instead an Ubuntu VM boots up in Parallels to launch Chromium. This is extremely annoying of course as it takes a lot of resources and takes a while to shut down again.
Here's my setup:
I am on macOS Catalina and have Parallels installed.
Inside Parallels, I have a Ubuntu VM:
Inside that Ubuntu VM, I have Chromium installed. This Chromium is registered in macOS as an app shortcut through Parallels:
This is NOT my default browser though. I use regular Chrome, and sometimes others for development, and have Choosy set as my default browser:
I would expect that better-opn
will always respect the choice I made in macOS system settings as my browser (i.e. exactly what would be picked if you run open https://github.com
on the command line).
But instead it always tries to launch Chromium for some reason, which is inside a VM and not my default browser.
When opening a browser tab, the title of the window where the process runs, changes to Windows PowerShell
.
This is undesirable, because:
This problem was first reported in #16192 @ Storybook.
TLDR: there is no way to change it back to what I meant for it to be, and there shouldn't need to be a way if better-opn left the window title alone.
Canary recently crashed and is using Google Chrome Dev,
However, better-OPn does not support the Dev version
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.