Skip to content

Commit e6f491a

Browse files
url capabilities
1 parent 718103e commit e6f491a

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/server.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Server.newSession = function(public,private, props)
1717
error("binary_location is required")
1818
end
1919

20-
local created = Session.newSession(private,{binary_location= props.binary_location,args=props.args})
20+
local created = Session.newSession(private, props)
2121
created.server = public
2222
return created
2323
end

src/session/constructor.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ Session.newSession = function (private_server_props,props)
3939
["goog:chromeOptions"] = {
4040
binary = props.binary_location,
4141
args =args,
42+
prefs={
43+
["download.default_directory"]= props.download_directory
44+
},
4245
excludeSwitches = {"enable-automation"},
4346
useAutomationExtension = use_automation_extension
4447
}

src/session/extra.lua

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,37 @@ PublicSession.get_session_id = function(public, private)
22
return private.session_id
33
end
44

5+
-- Retorna a quantidade de abas (janelas) abertas na sessão
6+
PublicSession.get_window_count = function(public, private)
7+
local result = private.fetch({
8+
url = private.url .. "/session/" .. private.session_id .. "/window/handles",
9+
method = "GET",
10+
http_version = "1.1"
11+
})
12+
if result.status_code ~= 200 then
13+
error("Failed to get window handles: " .. result.read_body())
14+
end
15+
local body = result.read_body_json()
16+
if not body.value or type(body.value) ~= "table" then
17+
error("Unexpected response for window handles")
18+
end
19+
return #body.value
20+
end
21+
22+
-- Retorna a URL da guia (janela) atual na sessão
23+
PublicSession.get_current_url = function(public, private)
24+
local result = private.fetch({
25+
url = private.url .. "/session/" .. private.session_id .. "/url",
26+
method = "GET",
27+
http_version = "1.1"
28+
})
29+
if result.status_code ~= 200 then
30+
error("Failed to get current URL: " .. result.read_body())
31+
end
32+
local body = result.read_body_json()
33+
if not body.value or type(body.value) ~= "string" then
34+
error("Unexpected response for current URL")
35+
end
36+
return body.value
37+
end
38+

0 commit comments

Comments
 (0)