glacambre / firenvim

Embed Neovim in Chrome, Firefox & others.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] pass eval_js result to lua functions

xudyang1 opened this issue · comments

  • OS Version: Windows 10 22H2
  • Browser Version: Chrome 120.0.6099.225
  • Browser Addon Version: 0.2.15
  • Neovim Plugin Version: commit 3363c14

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?

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.

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!