Skip to content

feat: Add support for options using native messaging#138

Open
Paniderez wants to merge 5 commits into
woodruffw:masterfrom
Paniderez:master
Open

feat: Add support for options using native messaging#138
Paniderez wants to merge 5 commits into
woodruffw:masterfrom
Paniderez:master

Conversation

@Paniderez

@Paniderez Paniderez commented Nov 14, 2025

Copy link
Copy Markdown

An expansion to woodruffw/ff2mpv#113, to send options through native messaging.

As referenced in gdh1995/vimium-c/issues#1077

Example of use using JS:

// Firefox
browser.runtime.sendMessage('ff2mpv@yossarian.net', { type: 'openVideo', url: 'https://someurl.com', options: '--ytdl-format=bestaudio[tbr<=?388]' })

Using vimium-c:
1.Add to Custom key mappings:

map <v-ff2mpv> sendToExtension id="ff2mpv@yossarian.net" raw
map vvv LinkHints.activateOpenUrl keyword="_opus"
  1. Add to Custom search engines:
_opus: vimium://run1/ff2mpv#data={"type":"openVideo","url":"$s","options":"--ytdl-format=bestaudio[tbr<=?388]"}

This is very useful, as you can now open different video resolutions using various key mappings.

Note: Currently can only send one option, i couldn't find a way to send multiple options. Hopefully someone can help with this.

@Paniderez

Copy link
Copy Markdown
Author

After further debugging i can certify that now can receive multiple options as seen here:

vimium-c debug console

image

ff2mpv debug console

image

The issue is from parsing the options message from vimium-c. But as for receiving the message with multiple options, it's good to go.

OS: Windows_NT 10.0 19045
Browser: Zen 1.17.6b
Vimium-c Version: 2.12.3

@DanSM-5

DanSM-5 commented Nov 14, 2025

Copy link
Copy Markdown
Contributor

The reason I didn't include options in there it is because it feels risky that any extension can send arbitrary flags that are eval'ed by python.

I would propose to add a request to get the profiles.

browser.runtime.sendMessage('ff2mpv@yossarian.net', { type: 'getProfiles' })
// returns list of profiles e.g. [{ name: 'foo', id: 'id' }]
// so calling extension can known available profiles
// "id" for identification and "name" for user facing display

Then improve the openVideo call to also allow to get a profileId.

browser.runtime.sendMessage('ff2mpv@yossarian.net', { type: 'openVideo', url: 'https://someurl.com', profileId: 'id' })

We then get the options from the profileId if provided and a matching profile exists. So we guarantee that only the options that the user entered are the only ones passed to python (u other backends).

@woodruffw

Copy link
Copy Markdown
Owner

Yeah, I think this should go through the existing profiles mechanism -- I strongly agree that allowing third-party extensions to pass arbitrary mpv flags without a user having to pre-configure them in a profile would represent a security risk.

@Paniderez

Copy link
Copy Markdown
Author

I've just resolve the two edge cases and confirm to work as expected from vimium-c console, as seen here:

getProfiles handler:
image

profileId integration with openVideo handler
image

So now from vimium-c:
1.Add to Custom key mappings:

map <v-ff2mpv> sendToExtension id="ff2mpv@yossarian.net" raw
map vvv LinkHints.activateOpenUrl keyword="_ff2mpv"
  1. Add to Custom search engines:
_ff2mpv: vimium://run1/ff2mpv#data={"type":"openVideo","url":"$s","profileId","(ff2mpv_profile_id)"}

@DanSM-5 @woodruffw Thank you for your clarification on the subject in matter.

@DanSM-5 DanSM-5 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor comments with the formatting but LGTM

Comment thread ff2mpv.js Outdated
switch (type) {
case OPEN_VIDEO:
ff2mpv(url);
let optionsPromise;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this line requires extra indentation

Comment thread ff2mpv.js Outdated
optionsPromise = Promise.resolve([]);
}
optionsPromise.then((options) => {
ff2mpv(url, tabId, options);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to ff2mpv and the return also requires some extra indentation :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants