Skip to content

Commit 3c95a10

Browse files
committed
ref: Target builds client and stores as instance var
1 parent d89a601 commit 3c95a10

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/ferrum/target.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ class Target
88
# where we enhance page class and build page ourselves.
99
attr_writer :page
1010

11-
attr_reader :session_id
11+
attr_reader :session_id, :options
1212

13-
def initialize(client, session_id = nil, params = nil)
13+
def initialize(browser_client, session_id = nil, params = nil)
1414
@page = nil
15-
@client = client
1615
@session_id = session_id
1716
@params = params
17+
@browser_client = browser_client
18+
@options = browser_client.options
1819
end
1920

2021
def update(params)
@@ -29,9 +30,13 @@ def page
2930
@page ||= build_page
3031
end
3132

33+
def client
34+
@client ||= build_client
35+
end
36+
3237
def build_page(**options)
3338
maybe_sleep_if_new_window
34-
Page.new(build_client, context_id: context_id, target_id: id, **options)
39+
Page.new(client, context_id: context_id, target_id: id, **options)
3540
end
3641

3742
def id
@@ -70,11 +75,13 @@ def maybe_sleep_if_new_window
7075
private
7176

7277
def build_client
73-
options = @client.options
74-
return @client.session(session_id) if options.flatten
78+
return @browser_client.session(session_id) if options.flatten
7579

76-
ws_url = options.ws_url.merge(path: "/devtools/page/#{id}").to_s
7780
Client.new(ws_url, options)
7881
end
82+
83+
def ws_url
84+
options.ws_url.merge(path: "/devtools/page/#{id}").to_s
85+
end
7986
end
8087
end

0 commit comments

Comments
 (0)