@@ -40,6 +40,7 @@ def create_session(capabilities)
4040 @bidi = Selenium ::WebDriver ::BiDi . new ( url : validated_socket_url )
4141 # Reuse the BiDi object's socket as the connection until the bridge owns it directly.
4242 @connection = @bidi . ws
43+ @current_window = window_handle
4344 rescue StandardError
4445 quit
4546 raise
@@ -57,23 +58,31 @@ def uninstall_web_extension(id)
5758 end
5859
5960 def get ( url )
60- browsing_context . navigate ( context : window_handle , url : url , wait : readiness_state )
61+ browsing_context . navigate ( context : @current_window , url : url , wait : readiness_state )
6162 nil
63+ rescue Error ::NoSuchFrameError => e
64+ raise Error ::NoSuchWindowError , e . message
6265 end
6366
6467 def go_back
65- browsing_context . traverse_history ( context : window_handle , delta : -1 )
68+ browsing_context . traverse_history ( context : @current_window , delta : -1 )
6669 nil
70+ rescue Error ::NoSuchFrameError => e
71+ raise Error ::NoSuchWindowError , e . message
6772 end
6873
6974 def go_forward
70- browsing_context . traverse_history ( context : window_handle , delta : 1 )
75+ browsing_context . traverse_history ( context : @current_window , delta : 1 )
7176 nil
77+ rescue Error ::NoSuchFrameError => e
78+ raise Error ::NoSuchWindowError , e . message
7279 end
7380
7481 def refresh
75- browsing_context . reload ( context : window_handle , wait : readiness_state )
82+ browsing_context . reload ( context : @current_window , wait : readiness_state )
7683 nil
84+ rescue Error ::NoSuchFrameError => e
85+ raise Error ::NoSuchWindowError , e . message
7786 end
7887
7988 def quit
@@ -88,6 +97,10 @@ def close
8897 execute ( :close_window ) . tap { |handles | bidi . close if handles . empty? }
8998 end
9099
100+ def switch_to_window ( name )
101+ super . tap { @current_window = name }
102+ end
103+
91104 private
92105
93106 def validated_socket_url
0 commit comments