woodruffw / ff2mpv

A Firefox/Chrome add-on for playing URLs in mpv.
https://addons.mozilla.org/en-US/firefox/addon/ff2mpv/
Other
492 stars 51 forks source link

Does not work on MacOS #124

Closed mlindner closed 2 months ago

mlindner commented 2 months ago

Describe the bug

Clicking the addon button when viewing a youtube page does precisely nothing.

In the console log its even further unhelpful. All I get is repeated:

Error: An unexpected error occurred

which the console says is reported from ffmpv.js:4:11 (line 4)

Reproduction steps

Go to any youtube site, click the addon button, observe nothing happening.

Expected behavior

A clear and concise description of what you expected to happen.

Platform information

Additional context (optional)

This is the third firefox linking to mpv addon I've tried and none of them work.

mlindner commented 2 months ago

I'll additionally add that mpv works just fine when I manually paste the link to it in the terminal, so it's not an issue with my mpv setup.

woodruffw commented 2 months ago

Can you confirm that you've installed the native client? This extension requires a native client to shuttle URLs between your browser and MPV; there are instructions for picking and installing one in the README.

Also: can you share your $PATH and the full path to your mpv binary? A common source of extension issues is (browser, OS) combinations not always spawning subprocesees with the user's shell-configured path.

mlindner commented 2 months ago

Yes I've installed the native client.

➜  ~ cat ~/Library/Application\ Support/Mozilla/NativeMessagingHosts/ff2mpv.json
{
    "name": "ff2mpv",
    "description": "ff2mpv's external manifest",
    "path": "/Users/lindner/sources/ff2mpv",
    "type": "stdio",
    "allowed_extensions": ["ff2mpv@yossarian.net"]
}
➜  ~ ls -l  ~/sources/ff2mpv
-rwxr-xr-x@ 1 lindner  staff  901 May  3 22:40 /Users/lindner/sources/ff2mpv*

Unless there's some other files than these two that need to be installed that aren't listed in the instructions on the wiki.

mpv is on my path of course otherwise I couldn't run it. It's just installed in the usual homebrew location and the homebrew directory is on my path. Scripts though often will be exec'd through some application without using the path though so that indeed may be the cause if you're not filling in the path correctly manually.

➜  ~ echo $PATH
/opt/homebrew/opt/qt@5/bin /Users/lindner/.cargo/bin /opt/homebrew/bin /opt/homebrew/sbin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Library/Apple/usr/bin /Library/Frameworks/Mono.framework/Versions/Current/Commands
➜  ~ which mpv
/opt/homebrew/bin/mpv

Also I'm using fish as my system shell so here's the fish paths.

➜  ~ echo $fish_user_paths
/opt/homebrew/opt/qt@5/bin /Users/lindner/.cargo/bin /opt/homebrew/bin /opt/homebrew/sbin
mlindner commented 2 months ago

As a side question, could you modify the addon to actually report useful information to the firefox console log? "Error: An unexpected error occurred" is about as useless of an error to report as you can possibly report. It should also cause a firefox popup with the error message rather than silently doing nothing. Via somthing like this that you can call with notify('message') (taken from another plugin's code):

var notify = message => chrome.notifications.create({
  type: 'basic',
  iconUrl: '/data/icons/48.png',
  title: chrome.i18n.getMessage('appTitle'),
  message
});

You can then even dump the mpv error stderr/stdout information into this as returned to the plugin.

woodruffw commented 2 months ago

Yes I've installed the native client.

Okay, thanks for confirming. I forgot to ask: are you using the Ruby one, the Python one, or a third-party one?

mpv is on my path of course otherwise I couldn't run it. It's just installed in the usual homebrew location and the homebrew directory is on my path. Scripts though often will be exec'd through some application without using the path though so that indeed may be the cause if you're not filling in the path correctly manually.

I understand it's on your shell's $PATH. I was asking about the application's $PATH, i.e. what you've said. On macOS in particular, graphical applications inherit their $PATH from a setting in launchd, which doesn't necessarily include your Homebrew path.

We have a pre-existing patch here that includes /opt/homebrew, so this shouldn't be what's affecting you:

https://github.com/woodruffw/ff2mpv/blob/4585f178bbb40414bfc7ba8689d4575853bca2e2/ff2mpv#L14-L21

Still, I need to ask since people frequently file bugs with custom Homebrew prefixes, custom MPV installs, etc. and are surprised when launchd doesn't include these in the default $PATH.

The only other well-known failure mode here is #89, where macOS's system-provided Python or Ruby (depending on native client choice) is aggressively sandboxed. Could you see if that affects you? (I suspect not since your native client is installed in ~/sources, but it's worth checking).

As a side question, could you modify the addon to actually report useful information to the firefox console log? "Error: An unexpected error occurred" is about as useless of an error to report as you can possibly report.

I'd be happy to review a PR for this. I'd prefer that it just use console.log however, since some third-party native clients already do error notifying (and not using notifications means we don't need that browser permission).

(Without a PR, I may do this eventually on my own, but no timeline promises. I maintain this plugin mostly for myself, this isn't an error mode I regularly run into, and I have my own patched native client that does notifications on Linux.)

mlindner commented 2 months ago

I'm using the ruby one. (The python one would have a .py extension.) Why are there two btw? Do they have different features?

As to the sandboxing thing I'm not fully sure how to test if that is the case. Nothing at all shows up in the console log when searching for ff2mpv. It's like ff2mpv is never running.

mlindner commented 2 months ago

Looking in the same console log for anything regarding mpv and I do see this when at about the timestamp when I run it:

AMFI: Denying core dump for pid 56688 (mpv)

Is mpv crashing somehow? Is there a way to reproduce the way you're launching it without going through firefox?

mlindner commented 2 months ago

I've discovered why it wasn't working. Apparently I had an old mpv install in /usr/loca/bin as well as the homebrew location and it was using that instead of the homebrew path. Because you're not getting the normal paths you apparently prioritized /usr/local/bin path instead of the homebrew path. I suggest swapping /usr/local/bin:/opt/homebrew/bin in your script because homebrew always puts its path before /usr/local/bin by default so this will match user configurations better. (It has to do this as there are many system installed older packages that the OS still uses but that homebrew needs to override for it to work with its own installs.)

mlindner commented 2 months ago

I removed the mpv in /usr/local/bin and things are now working.

woodruffw commented 2 months ago

Glad to hear it. If you feel like it, editing the troubleshooting page on the repo's wiki with your problem might be helpful to future users.

Because you're not getting the normal paths you apparently prioritized /usr/local/bin path instead of the homebrew path. I suggest swapping /usr/local/bin:/opt/homebrew/bin in your script because homebrew always puts its path before /usr/local/bin by default so this will match user configurations better. (It has to do this as there are many system installed older packages that the OS still uses but that homebrew needs to override for it to work with its own installs.)

Yes, this was done before ARM Macs were widespread. It probably makes sense to swap them now, so I'll do this.

(Everything below is my original response for continued debugging, preserved for posterity.)


I'm using the ruby one. (The python one would have a .py extension.) Why are there two btw? Do they have different features?

I wrote the Ruby one, I believe someone contributed the Python one a few years ago for hosts that don't have Ruby. They should have identical features.

Is mpv crashing somehow? Is there a way to reproduce the way you're launching it without going through firefox?

Looks like it, yeah. I'm not aware of a straightforward way to reproduce exactly what Firefox is doing, but you may be able to set the appropriate entitlement xattr to allow the core dump to proceed: https://forums.developer.apple.com/forums/thread/694233

In terms of the actual crash: I don't think anybody has reported this one macOS before, but some Linux users have reported issues where Firefox injects LD_LIBRARY_PATH or similar, overriding mpv's expected ffmpeg libraries. That manifested differently on Linux, but I suppose it could manifest as a crash (or forced abort/trap) on macOS.

mlindner commented 2 months ago

I submitted a pull request. https://github.com/woodruffw/ff2mpv/pull/125