This property acts like a Lua table with different behavior depending on how fields are accessed.
Calling a Chrome DevTools Protocol function
When getting this property, it will return a Chrome DevTools Protocol (CDP) function (that can be called with a JSON string).
The CDP function will then return a Task that, once finished, will return two values :
A boolean value indicating if the Chrome DevTools function succeeded
A string value representing either an error message in case of failure, or the function result as a JSON string
Setting a Chrome DevTools Protocol event function
When setting this property, a CDP event handler is defined using the provided Lua function.
Notes
The Chrome DevTools Protocol is a set of tools and APIs that allow developers to interact with, inspect, debug, and profile Chromium-based browsers like the Webview.
You can get CDP functions and set CDP events seamlessly with this property.
When defining an event handler function, make sure that event is spelled correctly.
You cannot use this property if the Webview is not ready.
local ui = require "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([[
]])
-- 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
ui.run(win):wait()