Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work in chromium browsers, but works in gecko browsers #122

Open
aljustiet opened this issue Apr 25, 2024 · 25 comments
Open

Does not work in chromium browsers, but works in gecko browsers #122

aljustiet opened this issue Apr 25, 2024 · 25 comments
Labels
B:chromium Support for Chromium-based browsers bug-candidate maybe a bug; not confirmed needs information P:linux

Comments

@aljustiet
Copy link

aljustiet commented Apr 25, 2024

I can't open videos in thorium browser using ff2mpv. I tried to use rust, ruby implementations, but they both don't work. Because of it I think the problem is in the script.

Reproduction steps

Steps to reproduce the behavior:

  1. Right click on the video and click “Open in MPV” in thorium.
  2. Does not play video in mpv

Expected behavior

Ability to play video in thorium browser.

Platform information

  • OS: Arch/Hyprland
  • thorium-browser-bin 124.0.6367.218-1
  • mpv 1:0.38.0-6
  • yt-dlp 2024.07.25-1

Edit: Works in the Brave browser

@aljustiet aljustiet added the bug-candidate maybe a bug; not confirmed label Apr 25, 2024
@woodruffw woodruffw added P:linux B:chromium Support for Chromium-based browsers labels May 4, 2024
@woodruffw
Copy link
Owner

Thanks for the report, and sorry for the delay.

Just to confirm: you've observed this plugin work in Firefox and Brave, but not in Chrome, right?

@aljustiet
Copy link
Author

bserved th

Right.

@justafreaky
Copy link

I have a similar problem. The extension works in Firefox, but does not work in Brave Browser.

@DanSM-5
Copy link
Contributor

DanSM-5 commented May 20, 2024

I had issues the other day with Brave in a mac pc. Turns out Brave does read the native messaging host of google chrome there as it does in windows. @justafreaky if you are on mac, try installing for chrome and see if that resolves your issue.

Repository owner deleted a comment from aljustiet Jul 24, 2024
@woodruffw
Copy link
Owner

Can anybody confirm that they're still observing these problems? We haven't received many other reports of Chromium-based browser breakage recently, so I suspect some of this is incorrect configurations (and if so, please help others by contributing to the wiki!)

@aljustiet
Copy link
Author

Can anybody confirm that they're still observing these problems? We haven't received many other reports of Chromium-based browser breakage recently, so I suspect some of this is incorrect configurations (and if so, please help others by contributing to the wiki!)

Here's how it doesn't play in mpv.

@DanSM-5
Copy link
Contributor

DanSM-5 commented Jul 27, 2024

Could you try placing the json manifest in Chrome's NativeMessagingHosts? Thorium may be reading that instead of its own.

@guest271314
Copy link
Contributor

Doesn't work out of the box on Chromium Version 129.0.6622.0 (Developer Build) (64-bit).

Some observations

  • The hardcoded extension id ephjcajbkgplkjmelpglennepbpmdpjg in ff2mpv-chromium.json will need to be updated when loading the unpacked extension
  • Should probably consider updating to Manifest 3
  • Errors are thrown at
Unrecognized manifest key 'applications'.

here

    "applications": {
        "gecko": {
            "id": "[email protected]",
            "strict_min_version": "50.0"
        }
    },

the Manifest 2 deprecation notice

Manifest version 2 is deprecated, and support will be removed in 2024. See https://developer.chrome.com/docs/extensions/develop/migrate/mv2-deprecation-timeline for details.

at

    "manifest_version": 2,

and

Uncaught (in promise) Error: Cannot find menu item with id ff2mpv

at browser-polyfill.js:792 (anonymous function)

            promise.reject(new Error(extensionAPIs.runtime.lastError.message));

@guest271314
Copy link
Contributor

Although this is probably not consequential for what's going on on Chromium-based browsers, this line

https://github.com/woodruffw/ff2mpv/blob/master/ff2mpv.py#L52

    content = json.dumps(message).encode("utf-8")

has an issue in that the JSON is formatted, includes spaces. Those space characters are counted as strings in the 1048576 length of message from host to client. See mdn/webextensions-examples#510 and mdn/content#23451. The fix in Python is

    content = json.dumps(message, separators=(',', ':')).encode('utf-8')

@DanSM-5
Copy link
Contributor

DanSM-5 commented Jul 28, 2024

Doesn't work out of the box on Chromium Version 129.0.6622.0 (Developer Build) (64-bit).
The hardcoded extension id ephjcajbkgplkjmelpglennepbpmdpjg in ff2mpv-chromium.json will need to be updated when loading the unpacked extension

That's chromium's behavior. Only way to keep the extension id is to publish it to the store. If you install it from the store, it should use that extension id but if you load it as an unpacked extension, it will change every time and you'll need to manually update the json manifest.

Latest stable chrome is 127 and I can see the deprecation warning but ff2mpv still works there.

Are you unable to install from the store in chrome 129?

Should probably consider updating to Manifest 3

It is almost done: #70

I understood that firefox didn't have support for service workers under MV3 yet, so the PR hasn't been merged. I haven't kept up with the deadlines for MV2 deprecation, so not sure when the extension will stop working.

@woodruffw
Copy link
Owner

Agreed with everything @DanSM-5 said -- we don't currently support versions of Chrome/Chromium outside of stable channels (because of things like the MV2 -> MV3 transition). This could be documented better; you can help us out by putting a note on the wiki.


Separately: @guest271314, would you be interested in sending a PR for that change? I don't think we're anywhere close to the 1MB message limit in this extension, but minimizing anyways doesn't seem like a bad idea.

@guest271314
Copy link
Contributor

@woodruffw Sure. I would suggest updating your code to use Manifest 3. And use web-ext if necessary to create discrete Firefox and Chromium extensions.

The bug is real here. At some point soon you're going to need to update this.

If all the extension does is accept a URL and send that to mpv the code could be reduced substantially.

@guest271314
Copy link
Contributor

@DanSM-5

That's chromium's behavior. Only way to keep the extension id is to publish it to the store. If you install it from the store, it should use that extension id but if you load it as an unpacked extension, it will change every time and you'll need to manually update the json manifest.

That's chromium's behavior. Only way to keep the extension id is to publish it to the store. If you install it from the store, it should use that extension id but if you load it as an unpacked extension, it will change every time and you'll need to manually update the json manifest.

Latest stable chrome is 127 and I can see the deprecation warning but ff2mpv still works there.

Are you unable to install from the store in chrome 129?

Frankly, I don't install extensions from Chrome Web Store or Firefox's equivalent. I only load unpacked extensions that I write or from sources on GitHub where I can read the source code.

I was just conveying that I would update the README/instructions to include the fact the dynamically generated extension ID needs to be updated manulally, or programmatically, if you want. E.g., https://github.com/guest271314/NativeMessagingHosts?tab=readme-ov-file#installation-and-usage

  1. Navigate to chrome://extensions.
  2. Toggle Developer mode.
  3. Click Load unpacked.
  4. Select native-messaging-quickjs folder.
  5. Note the generated extension ID.
  6. Open, for example, nm_c_wasm.json in a text editor, set "path" to absolute path of nm_c.wasm and chrome-extension://<ID>/ using ID from 5 in "allowed_origins" array.
  7. Copy the nm_c_wasm.json file to Chrome or Chromium configuration folder, e.g., Chromium on *nix ~/.config/chromium/NativeMessagingHosts; Chrome dev channel on *nix ~/.config/google-chrome-unstable/NativeMessagingHosts.
  8. Make sure wasmtime for WASM host, or the single host file, e.g. when using QuickJS nm_qjs.js, are executable.
  9. To test click service worker link in panel of unpacked extension which is DevTools for background.js in MV3 ServiceWorker, observe echo'ed message from Native Messaging host to client in DevTools console. To disconnect run port.disconnect().

Technically that should only need to be done once, as the extension ID will not change once generated and you use the same extension code, or update the code. I have extensions I wrote I have used for years where the extension ID doesn't change.

@guest271314
Copy link
Contributor

#126

@aljustiet
Copy link
Author

It now works both and chrome and brave, but not on thorium 124.0.6367.218.

@woodruffw
Copy link
Owner

I would suggest updating your code to use Manifest 3. And use web-ext if necessary to create discrete Firefox and Chromium extensions.

#70 will do this. If more people want to demo-run the changes in that PR and confirm that they work for them, then I'll happily merge them and make a release that uses MV3 instead.

I was just conveying that I would update the README/instructions to include the fact the dynamically generated extension ID needs to be updated manulally, or programmatically, if you want. E.g., guest271314/NativeMessagingHosts#installation-and-usage

Please feel free to contribute this to the wiki -- 99% of users are loading directly from AMO or the Chrome Store, so IMO putting it in the README is likely to confuse those users. But a dedicated section on the troubleshooting page is probably a good fit for it.

@guest271314
Copy link
Contributor

#70 will do this. If more people want to demo-run the changes in that PR and confirm that they work for them, then I'll happily merge them and make a release that uses MV3 instead.

For unpacked extension installed from GitHub repository we still have to set the generated extension ID. Not a big deal. Makes sure people in the field have to actuall do something other than press go to start using Native Messaging. Requires some human action.

git clone --branch=pr/mv3 https://github.com/eNV25/ff2mpv

chrome://extensions?errors

'background.scripts' requires manifest version of 2 or lower.
Unrecognized manifest key 'browser_specific_settings'.
    "browser_specific_settings": {
        "gecko": {
            "id": "[email protected]",
            "strict_min_version": "50.0"
        }
    }
Unchecked runtime.lastError: Cannot find menu item with id ff2mpv
:0 (anonymous function)

@guest271314
Copy link
Contributor

In manfifest.json we can remove the following to get rid of the first two errors

        "scripts": ["ff2mpv.js"],

and

    "browser_specific_settings": {
        "gecko": {
            "id": "[email protected]",
            "strict_min_version": "50.0"
        }
    },

then we're just left with

Unchecked runtime.lastError: Cannot find menu item with id ff2mpv

@DanSM-5
Copy link
Contributor

DanSM-5 commented Jul 28, 2024

then we're just left with

Unchecked runtime.lastError: Cannot find menu item with id ff2mpv

I know why this one is happening. When the background script starts there is no registered context menu with id ff2mpv:

  browser.contextMenus.remove('ff2mpv');

Maybe using await contextMenus.removeAll() in a try/catch will help to suppress the error. Other than that, the error should be harmless for the functionality of the extension.

@guest271314
Copy link
Contributor

This doesn't change anything

chrome.runtime.onInstalled.addListener(async (_) => {
  console.log(await chrome.contextMenus.remove("ff2mpv"));

@guest271314
Copy link
Contributor

This works

function changeToSingleEntry() {
  // Remove sub context menu
  try {
    chrome.contextMenus.removeAll();

I get to the message from the Native Messaging host, "ok", however looks like the version of mpv I have on the machine is not parsing the URL of a youtube video, on the commandline

 mpv https://www.youtube.com/watch?v=JnyBQQnfeqk
[ytdl_hook] ERROR: [youtube] JnyBQQnfeqk: Unable to extract uploader id; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U 
[ytdl_hook] youtube-dl failed: unexpected error occurred 
Failed to recognize file format.

Exiting... (Errors when loading file)

@guest271314
Copy link
Contributor

I can very the Python script works, until I build mpv from GitHub repository I changed the command to this, which works

    args = ["/home/user/chrome-linux/chrome", "--password-store=basic", "--user-data-dir=/home/user/ff2mpv", "--window-size=600,400", url]

@guest271314
Copy link
Contributor

Got it working with a local file, just to make just mpv is being launched

    args = ["mpv", "--no-terminal", *options, "--", "/home/user/ff2mpv/movie.ogv"]

@guest271314
Copy link
Contributor

By works I mean launches mpv. I don't get any ff2mpv option in a context menu, I click the action icon.

@DanSM-5
Copy link
Contributor

DanSM-5 commented Jul 28, 2024

I've created a PR for the issue with runtime.lastError eNV25#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B:chromium Support for Chromium-based browsers bug-candidate maybe a bug; not confirmed needs information P:linux
Projects
None yet
Development

No branches or pull requests

5 participants