finicky icon indicating copy to clipboard operation
finicky copied to clipboard

Args not working on latest version

Open REBELinBLUE opened this issue 6 months ago • 1 comments

⚠️ Please note that only Finicky 4 is being actively developed and maintained, bugs in Finicky 3 and below won't be fixed

Describe the bug I upgraded to v4 and refactored my config and now args isn't working

Your configuration I have the following config

// @ts-check

/**
 * @typedef {import('/Applications/Finicky.app/Contents/Resources/finicky.d.ts').FinickyConfig} FinickyConfig
 */

/**
 * @type {FinickyConfig}
 */
export default {
  defaultBrowser: "Safari",
  options: {
    checkForUpdates: true,
    logRequests: true,
  },
  rewrite: [],
  handlers: [
    {
      match: (url, options) => {
          if (options.opener != null && options.opener.bundleId == "com.bluebanana-software.inyourface") {
              return url.host.includes("google.com")
          }

          return url.host.startsWith("meet.google.com") || url.host.startsWith("accounts.google.com")
      },
      browser: (url) => ({
          name: "Google Chrome",
          args: [
              '--app-id=kjgfgldnnfoeklkmfkjfagphfepbbdan',
              `--app-launch-url-for-shortcuts-menu-item=${url.toString()}`,
          ]
      })
    },
    {
      match: /^^https?:\/\/www.google.com\/calendar\/event.*$/,
      browser: "Google Chrome"
    },
    {
      match: /^https?:\/\/(accounts|docs|sheets|slides|mail|drive|calendar|groups|admin)\.google\.com.*$/,
      browser: "Google Chrome"
    },
    {
      match: /^https?:\/\/forms\.gle.*$/,
      browser: "Google Chrome"
    },
    {
      match: /^https?:\/\/lendinvest\.logicgate\.com.*$/,
      browser: "Google Chrome"
    }
  ]
}

To Reproduce Launch a google meets link

Nothing happens but in the console of finicky I see the following

command: open -a 'Google Chrome' --app-id=kjgfgldnnfoeklkmfkjfagphfepbbdan '--app-launch-url-for-shortcuts-menu-item=[https://meet.google.com/[email protected]'](https://meet.google.com/[email protected]%27)
10:04:59
Command returned error
Error: open: unrecognized option `--app-id=kjgfgldnnfoeklkmfkjfagphfepbbdan'
Usage: open [-e] [-t] [-f] [-W] [-R] [-n] [-g] [-h] [-s <partial SDK name>][-b <bundle identifier>] [-a <application>] [-u URL] [filenames] [--args arguments]
Help: Open opens files from a shell.
      By default, opens each file using the default application for that file.  
      If the file is in the form of a URL, the file will be opened as a URL.
Options: 
      -a                    Opens with the specified application.
      --arch ARCH           Open with the given cpu architecture type and subtype.
      -b                    Opens with the specified application bundle identifier.
      -e                    Opens with TextEdit.
      -t                    Opens with default text editor.
      -f                    Reads input from standard input and opens with TextEdit.
      -F  --fresh           Launches the app fresh, that is, without restoring windows. Saved persistent state is lost, excluding Untitled documents.
      -R, --reveal          Selects in the Finder instead of opening.
      -W, --wait-apps       Blocks until the used applications are closed (even if they were already running).
          --args            All remaining arguments are passed in argv to the application's main() function instead of opened.
      -n, --new             Open a new instance of the application even if one is already running.
      -j, --hide            Launches the app hidden.
      -g, --background      Does not bring the application to the foreground.
      -h, --header          Searches header file locations for headers matching the given filenames, and opens them.
      -s                    For -h, the SDK to use; if supplied, only SDKs whose names contain the argument value are searched.
                            Otherwise the highest versioned SDK in each platform is used.
      -u, --url URL         Open this URL, even if it matches exactly a filepath
      -i, --stdin  PATH     Launches the application with stdin connected to PATH; defaults to /dev/null
      -o, --stdout PATH     Launches the application with /dev/stdout connected to PATH; 
          --stderr PATH     Launches the application with /dev/stderr connected to PATH to
          --env    VAR      Add an enviroment variable to the launched process, where VAR is formatted AAA=foo or just AAA for a null string value.
10:04:59
Failed to start browser
Error: command failed: exit status 1

This is the output from macOS open command when --args is missing. The only place I can see args being set is here https://github.com/johnste/finicky/blob/main/apps/finicky/src/browser/launcher.go#L74 but it is setting it if the length of args is 0?

REBELinBLUE avatar Jun 02 '25 09:06 REBELinBLUE

I seem to have been able to work around it by adding --args as the first item in args

REBELinBLUE avatar Jun 02 '25 10:06 REBELinBLUE

Not sure adding --args worked actually, it just opens chrome but not the app, in the troubleshoot I can see

Run command
command: open -a 'Google Chrome' --args --app-id=kjgfgldnnfoeklkmfkjfagphfepbbdan --app-launch-url-for-shortcuts-menu-item=https://meet.google.com/123-qwert-asd

if I run that from terminal it also just opens chrome, but if I run

open -a 'Google Chrome' --args '--app-id=kjgfgldnnfoeklkmfkjfagphfepbbdan' '--app-launch-url-for-shortcuts-menu-item=https://meet.google.com/123-qwert-asd'

it works, however if I quote the args in the args array it then does

Run command
command: open -a 'Google Chrome' --args '"--app-id=kjgfgldnnfoeklkmfkjfagphfepbbdan"' '"--app-launch-url-for-shortcuts-menu-item=https://meet.google.com/123-qwert-asd"'

REBELinBLUE avatar Jun 05 '25 15:06 REBELinBLUE

Same here, I just tried migrating from V3 to V4 and I can't seem to get this to work. the --args workaround opened the browser, but the URL doesn't get opened.

fa7ad avatar Jun 10 '25 14:06 fa7ad

For me, workaround works just fine if chrome is not open yet. The same is reproducible directly from terminal

open -a 'Google Chrome' --args '--app-id=...'

It won't start the app (just focus google chrome) unless google chrome is not running. Not sure how finicky was making it work before.

So, the issue might not be in the finicky but e.g. in open command or Chrome itself, which previous version of finicky was somehow making it work.


UPDATE

Ok, found an issue. It was in open command. If I start chrome with open -a or open -b, it just ignores '--app-id=...' argument. Starting Chrome only with -n '/path/to/Google Chrome.app (usually '/Applications/Google Chrome.app') works just fine.

Since the only way to get open started with -n is to have profile and to do not have args as per https://github.com/johnste/finicky/blob/d218e0a36b0ec3cc5fdc868baed52357ae032211/apps/finicky/src/browser/launcher.go#L73 There is no way to make it fully working with current Finicky implementation


UPDATE 2 It's possible to create custom apple script app with Automator which would later open Google Chrome with -n

kopach avatar Jun 16 '25 09:06 kopach

https://github.com/johnste/finicky/blob/v3.4.0/Finicky/Finicky/Browsers.swift#L60-L64 the old version does seem to potentially add -a or -b but there is also a case where it does neither but yeah on the current code it always adds one or the other

@johnste any comment on this? thanks

REBELinBLUE avatar Jun 18 '25 11:06 REBELinBLUE

Any updates?

mionstew avatar Jun 29 '25 11:06 mionstew

Looks like args aren't passed on like intended, I'll have a look

johnste avatar Jun 30 '25 05:06 johnste

@johnste I am not sure it is working quite right still

it runs open -a 'Google Chrome' --args --app-id=kjgfgldnnfoeklkmfkjfagphfepbbdan '--app-launch-url-for-shortcuts-menu-item=https://meet.google.com/[email protected] but as @kopach said, that doesn't work if Chrome is already running.

In v3 I was able to do if whether Chrome was already running or not

using open -n '/Applications/Google Chrome.app' works regardless of whether Chrome is already running or not

REBELinBLUE avatar Jul 02 '25 15:07 REBELinBLUE

I suppose, adding profile: 'my profile' to

browser: (url) => ({
          name: "Google Chrome",
          args: [
              '--app-id=kjgfgldnnfoeklkmfkjfagphfepbbdan',
              `--app-launch-url-for-shortcuts-menu-item=${url.toString()}`,
          ]
      })

works as a workaround

REBELinBLUE avatar Jul 02 '25 16:07 REBELinBLUE

Oh, sorry. I'm not using any PWAs myself so I guess I didn't really test properly.

So PWAs like these only really work with the -n flag?

johnste avatar Jul 02 '25 16:07 johnste

Not really sure to be honest, but it does look that way

REBELinBLUE avatar Jul 02 '25 16:07 REBELinBLUE

It would be very helpful if someone could provide me with command line examples that work well for this

johnste avatar Jul 02 '25 16:07 johnste

open -n '/Applications/Google Chrome.app' --args --app-id=kjgfgldnnfoeklkmfkjfagphfepbbdan '--app-launch-url-for-shortcuts-menu-item=https://meet.google.com/[email protected]

works in both cases for me

REBELinBLUE avatar Jul 02 '25 16:07 REBELinBLUE

The -n is required for Firefox to work with args as well. Here's what I have that works in 4.1.3 but not in 4.1.4:

browser: (url) => ({
  name:  "Firefox",
  args: ["-n", "--args", "-new-window", `${url.href}`],
})

4.1.4 ends up adding another --args to the front so that the -n argument for open gets ignored.

I'm not really sure the best way to handle this. We could maybe add an open_args key to pass arguments to open so it'd be something like:

browser: (url) => ({
  name:  "Firefox",
  open_args: ["-n"],
  args: ["-new-window", `${url.href}`],
})

Or users could just be instructed to add --args to the args key themselves if they need it.

kevinjfoley avatar Jul 07 '25 21:07 kevinjfoley

Love the discussion! Also not sure what the best approach is - I like the idea of the app being browser agnostic but that would maybe lead to an increasingly complex configuration.

johnste avatar Jul 08 '25 06:07 johnste

What if we checked for --args in args and if it's found we don't add it again?

In case it's helpful, here's the few options I can think of listed out:

1. Check for --args in args and don't add it again if it's found

Pros:

  • Should be backwards compatible

Cons:

  • Adds complexity to the code
    • I think it's minor but I'm not too familiar with the code
  • Could conflict with a browser that takes --args as an argument
    • This seems unlikely
    • If it does happen the user should be able to resolve it by adding a second --args

2. Don't try to add --args at all

Pros:

  • Simplifies code
  • Gives user full control

Cons:

  • Not backwards compatible

3. Add open_args option

Pros:

  • I can't think of any over the other options

Cons:

  • Add complexity to both code and configuration

Assuming all of the above is accurate, I think option 1 makes sense. If you agree @johnste I'm happy to try to put together a PR.

kevinjfoley avatar Jul 09 '25 01:07 kevinjfoley

Just released v4.2.1 which should fix this issue.

johnste avatar Sep 17 '25 18:09 johnste