From 8604765c3660dbea9cae6996d5750bfb985e6751 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 27 Jul 2025 20:21:07 +0530 Subject: Add web.view.run_js + change rpc js api --- lua/null-browser/api.lua | 17 ++++++++++++++++- lua/null-browser/extras/tabline.lua | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/null-browser/api.lua b/lua/null-browser/api.lua index 07b7072..5475beb 100644 --- a/lua/null-browser/api.lua +++ b/lua/null-browser/api.lua @@ -129,6 +129,21 @@ function web.view.set_url(url, view_id) return __internals.view_set_url(url, vie --- ``` function web.view.set_html(html, opts) return __internals.view_set_html(html, (opts or {}).view) end +--- @class RunJSOpts +--- @field view? number View id + +--- Set html in a given view +--- +--- @param js string HTML string +--- @param opts? RunJSOpts Options +--- +--- @example +--- ```lua +--- web.view.run_js('console.log(42)') +--- web.view.run_js('console.log(42)', 3) -- Set html for view with id 3 +--- ``` +function web.view.run_js(js, opts) return __internals.view_run_js(js, (opts or {}).view) end + --- @class ExposeOpts --- @field view? number View id @@ -146,7 +161,7 @@ function web.view.set_html(html, opts) return __internals.view_set_html(html, (o --- ``` --- then in js --- ```js ---- __nullbrowser.tab_select({ view: 5 }) +--- _nullbrowser.rpc.tab_select({ view: 5 }) --- ``` function web.view.expose(name, action, opts) return __internals.view_expose(name, action, (opts or {}).view) end diff --git a/lua/null-browser/extras/tabline.lua b/lua/null-browser/extras/tabline.lua index b9156f5..e265940 100644 --- a/lua/null-browser/extras/tabline.lua +++ b/lua/null-browser/extras/tabline.lua @@ -47,7 +47,7 @@ function tabline.tabs_html() for index, view in ipairs(web.view.list()) do local tab = html.button({ class = 'tab' .. (web.view.current() == view.id and ' current' or ''), - onclick = '__nullbrowser.tab_select({ view: ' .. view.id .. ' })', + onclick = '_nullbrowser.rpc.tab_select({ view: ' .. view.id .. ' })', }, { index .. ': ' .. view.title .. ' (' .. view.url .. ')', }) -- cgit v1.3.1