Giter Site home page Giter Site logo

michaellzc / better-opn Goto Github PK

View Code? Open in Web Editor NEW
39.0 2.0 7.0 916 KB

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

JavaScript 74.96% AppleScript 25.04%
opn open

better-opn's People

Contributors

dependabot[bot] avatar erezrokah avatar jfirebaugh avatar michaellzc avatar otakustay avatar richorrichard avatar yannbf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

better-opn's Issues

Pass only host to applescript

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.

Colon-delimitation of commands in `BROWSER` is not respected

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 as EDITOR or PAGER - it is not mentioned by the standards. However, some programs may use them, like man:

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.

Contribute the features back to upstream `open`?

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.

Should respect OS user preferences rather than default to a "better" browser

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.

this url will open twice

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 '&'

Browser not opened on Windows ARM64

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.

Query on setting the default command shell

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'
}

87878787

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

987987987

Instead of opening my default macOS browser, opens Ubuntu VM through Parallels with Chromium

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:

image

Inside that Ubuntu VM, I have Chromium installed. This Chromium is registered in macOS as an app shortcut through Parallels:

Chromium shortcut

This is NOT my default browser though. I use regular Chrome, and sometimes others for development, and have Choosy set as my default browser:

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

Opening browser causes a change in the window title

When opening a browser tab, the title of the window where the process runs, changes to Windows PowerShell.

This is undesirable, because:

  1. It's too generic to recognize on the task bar among other command prompt windows.
  2. The application had changed it priorly to something meaningful, in my case.

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.

add googel chrome dev

Canary recently crashed and is using Google Chrome Dev,
However, better-OPn does not support the Dev version

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.