Webview.cdp
This property acts like a Lua table with different behavior depending on how fields are accessed.
Calling a Chrome DevTools Protocol function
Example
--! luart-extensions
import ui
require "webview"
local win = ui.Window("Chrome Devtools Protocol event example", "fixed", 320, 240)
local wv = ui.Webview(win, 0, 0, 320, 200)
wv.align = "all"
win:center()
function wv:onReady()
self:loadstring([[
<html>
<body><div style="display: flex; justify-content: center; align-items: center; height: 90vh;">
<button onclick="window.open('https://www.luart.org', '_blank', 'width=600,height=400')">Open new window</button>
</div></body>
</html>]])
-- enable CDP Page events
wv.cdp.Page.enable()
-- set a CDP Page.windowOpen() event
function wv.cdp.Page.windowOpen()
ui.info("New window detected")
end
end
await win:showasync()