Skip to content

Commit 284a2df

Browse files
added execute_cmd
1 parent 9bf146c commit 284a2df

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/session/extra.lua

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,38 @@ PublicSession.close = function (public, private)
1818
private.closed = true
1919
end
2020

21+
22+
23+
-- Add this function to PublicSession
24+
PublicSession.execute_cdp_cmd = function(public, private, cmd, params)
25+
if not cmd or type(cmd) ~= "string" then
26+
error("CDP command must be a non-empty string")
27+
end
28+
29+
-- Default to empty params if not provided
30+
if not params then
31+
params = {}
32+
end
33+
34+
local result = private.fetch({
35+
url = private.url .. "/session/" .. private.session_id .. "/goog/cdp/execute",
36+
method = "POST",
37+
http_version = "1.1",
38+
body = {
39+
cmd = cmd,
40+
params = params
41+
}
42+
})
43+
44+
if result.status_code ~= 200 then
45+
local error_body = result.read_body()
46+
error("Failed to execute CDP command '" .. cmd .. "': " .. (error_body or "Unknown error"))
47+
end
48+
49+
local body = result.read_body_json()
50+
return body.value
51+
end
52+
2153
-- Retorna a quantidade de abas (janelas) abertas na sessão
2254
PublicSession.get_window_count = function(public, private)
2355
local result = private.fetch({

0 commit comments

Comments
 (0)