Class: Selenium::WebDriver::BiDi::Network

Inherits:
Object
  • Object
show all
Defined in:
rb/lib/selenium/webdriver/bidi/network.rb

Constant Summary collapse

EVENTS =
{
  before_request: 'network.beforeRequestSent',
  response_started: 'network.responseStarted',
  response_completed: 'network.responseCompleted',
  auth_required: 'network.authRequired',
  fetch_error: 'network.fetchError'
}.freeze
PHASES =
{
  before_request: 'beforeRequestSent',
  response_started: 'responseStarted',
  auth_required: 'authRequired'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(bidi) ⇒ Network

Returns a new instance of Network.



39
40
41
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 39

def initialize(bidi)
  @bidi = bidi
end

Instance Method Details

#add_intercept(phases: [], contexts: nil, url_patterns: nil, pattern_type: :string) ⇒ Object



43
44
45
46
47
48
49
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 43

def add_intercept(phases: [], contexts: nil, url_patterns: nil, pattern_type: :string)
  url_patterns = url_patterns && pattern_type ? UrlPattern.format_pattern(url_patterns, pattern_type) : nil
  @bidi.send_cmd('network.addIntercept',
                 phases: phases,
                 contexts: contexts,
                 urlPatterns: url_patterns)
end

#cancel_auth(request_id) ⇒ Object



76
77
78
79
80
81
82
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 76

def cancel_auth(request_id)
  @bidi.send_cmd(
    'network.continueWithAuth',
    request: request_id,
    action: 'cancel'
  )
end

#continue_request(**args) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 84

def continue_request(**args)
  @bidi.send_cmd(
    'network.continueRequest',
    request: args[:id],
    body: args[:body],
    cookies: args[:cookies],
    headers: args[:headers],
    method: args[:method],
    url: args[:url]
  )
end

#continue_response(**args) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 103

def continue_response(**args)
  @bidi.send_cmd(
    'network.continueResponse',
    request: args[:id],
    cookies: args[:cookies],
    credentials: args[:credentials],
    headers: args[:headers],
    reasonPhrase: args[:reason],
    statusCode: args[:status]
  )
end

#continue_with_auth(request_id, username, password) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 55

def continue_with_auth(request_id, username, password)
  @bidi.send_cmd(
    'network.continueWithAuth',
    request: request_id,
    action: 'provideCredentials',
    credentials: {
      type: 'password',
      username: username,
      password: password
    }
  )
end

#continue_without_auth(request_id) ⇒ Object



68
69
70
71
72
73
74
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 68

def continue_without_auth(request_id)
  @bidi.send_cmd(
    'network.continueWithAuth',
    request: request_id,
    action: 'default'
  )
end

#fail_request(request_id) ⇒ Object



96
97
98
99
100
101
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 96

def fail_request(request_id)
  @bidi.send_cmd(
    'network.failRequest',
    request: request_id
  )
end

#on(event, &block) ⇒ Object



131
132
133
134
135
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 131

def on(event, &block)
  event = EVENTS[event] if event.is_a?(Symbol)
  @bidi.add_callback(event, &block)
  @bidi.session.subscribe(event)
end

#provide_response(**args) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 115

def provide_response(**args)
  @bidi.send_cmd(
    'network.provideResponse',
    request: args[:id],
    body: args[:body],
    cookies: args[:cookies],
    headers: args[:headers],
    reasonPhrase: args[:reason],
    statusCode: args[:status]
  )
end

#remove_intercept(intercept) ⇒ Object



51
52
53
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 51

def remove_intercept(intercept)
  @bidi.send_cmd('network.removeIntercept', intercept: intercept)
end

#set_cache_behavior(behavior, *contexts) ⇒ Object



127
128
129
# File 'rb/lib/selenium/webdriver/bidi/network.rb', line 127

def set_cache_behavior(behavior, *contexts)
  @bidi.send_cmd('network.setCacheBehavior', cacheBehavior: behavior, contexts: contexts)
end