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

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

Open
xudyang1 opened this issue Apr 10, 2024 · 3 comments
Open

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

xudyang1 opened this issue Apr 10, 2024 · 3 comments

Comments

@xudyang1
Copy link
Contributor

  • 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?

@glacambre
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link

BWindey commented Nov 19, 2024

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, ...

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

No branches or pull requests

3 participants