Module: Ferrum::Page::Net
- Included in:
- Ferrum::Page
- Defined in:
- lib/ferrum/page/net.rb
Constant Summary collapse
- AUTHORIZE_TYPE =
i[server proxy]
- RESOURCE_TYPES =
%w[Document Stylesheet Image Media Font Script TextTrack XHR Fetch EventSource WebSocket Manifest SignedExchange Ping CSPViolationReport Other]
Instance Method Summary collapse
- #abort_request(interception_id) ⇒ Object
- #authorize(user:, password:, type: :server) ⇒ Object
- #continue_request(interception_id, options = nil) ⇒ Object
- #intercept_request(pattern: "*", resource_type: nil) ⇒ Object
Instance Method Details
#abort_request(interception_id) ⇒ Object
52 53 54 |
# File 'lib/ferrum/page/net.rb', line 52 def abort_request(interception_id) continue_request(interception_id, errorReason: "Aborted") end |
#authorize(user:, password:, type: :server) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ferrum/page/net.rb', line 11 def (user:, password:, type: :server) unless AUTHORIZE_TYPE.include?(type) raise ArgumentError, ":type should be in #{AUTHORIZE_TYPE}" end ||= {} [type] ||= [] intercept_request on(:request_intercepted) do |request, index, total| if request.auth_challenge?(type) response = ([type], request.interception_id, user, password) [type] << request.interception_id request.continue(authChallengeResponse: response) elsif index + 1 < total next # There are other callbacks that can handle this, skip else request.continue end end end |
#continue_request(interception_id, options = nil) ⇒ Object
46 47 48 49 50 |
# File 'lib/ferrum/page/net.rb', line 46 def continue_request(interception_id, = nil) ||= {} = .merge(interceptionId: interception_id) command("Network.continueInterceptedRequest", **) end |
#intercept_request(pattern: "*", resource_type: nil) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/ferrum/page/net.rb', line 37 def intercept_request(pattern: "*", resource_type: nil) pattern = { urlPattern: pattern } if resource_type && RESOURCE_TYPES.include?(resource_type.to_s) pattern[:resourceType] = resource_type end command("Network.setRequestInterception", patterns: [pattern]) end |