glacambre / firenvim

Embed Neovim in Chrome, Firefox & others.
GNU General Public License v3.0
4.81k stars 147 forks source link

[Feature Request] pass eval_js result to lua functions #1599

Open xudyang1 opened 7 months ago

xudyang1 commented 7 months ago

What I tried to do

I was testing firenvim#eval_js on the browser to retrieve page informatino so that I can decide {extension} in filename based on the result.

Here is an example command when invoke in firenvim's homepage:

:lua vim.fn['firenvim#eval_js']('document.querySelector("#repo-content-turbo-frame > div > div > div.Layout.Layout--flowRow-until-md.react-repos-overview-margin.Layout--sidebarPosition-end.Layout--sidebarPosition-flowRow-end > div.Layout-sidebar > div > div:nth-child(1) > div > div > p").innerHTML', 'vim.print')

What happened

Neovim got nothing in :message, and the browser logged

Uncaught (in promise) > (2) [0, 'Vim:E117: Unknown function: vim.print']
                        0 : 0
                        1 : "Vim:E117: Unknown function: vim.print"

It looks like eval_js can only work with vimscript/functions/apis, and neovim's apis are not recognized. Support for neovim's apis/lua functions reduces the overhead of writing vimscript in lua config files. If this feature is not planned, maybe we can provide some examples for users who like to write some vimscript in lua config files?

glacambre commented 7 months ago

Hi, thanks for opening this issue. eval_js only supporting VimScript callbacks is indeed quite unfortunate, this is not something I would implement today.

Unfortunately, eval_js is likely to stop working altogether soon when Firenvim is migrated to Manifest V3 (the new WebExtension API Chrome is forcing every extension to migrate to). Because of this, I would recommend not relying on eval_js. If there is still a way to make eval_js work with Manifest V3, I'll rework it to make it support lua callbacks too.

xudyang1 commented 7 months ago

Hi, thanks for opening this issue. eval_js only supporting VimScript callbacks is indeed quite unfortunate, this is not something I would implement today.

Unfortunately, eval_js is likely to stop working altogether soon when Firenvim is migrated to Manifest V3 (the new WebExtension API Chrome is forcing every extension to migrate to). Because of this, I would recommend not relying on eval_js. If there is still a way to make eval_js work with Manifest V3, I'll rework it to make it support lua callbacks too.

Thank you for the detailed explanation! Firenvim already does its awesome job as a text editor in webpages. If eval_js supports lua script and vim.api in the future, it will definitely help users in interacting with DOM apis!

BWindey commented 4 days ago

So is there no way to get info about the page currently? I would like to search the page HTML for a certain tag and set the extension. The alternative would be making an API-call in my case, but then I need the API-key, set up https in my vim-config, set the right https-headers, ...