class Playwright::HarRouter

def self.create(local_utils, file, not_found_action, url_match: nil)

Parameters:
  • url_match (String||Regexp|nil) --
  • not_found_action (String) -- 'abort' or 'fallback'
  • file (String) --
  • local_utils (LocalUtils) --
def self.create(local_utils, file, not_found_action, url_match: nil)
  har_id = local_utils.har_open(file)
  new(
    local_utils: local_utils,
    har_id: har_id,
    not_found_action: not_found_action,
    url_match: url_match,
  )
end

def add_context_route(context)

def add_context_route(context)
  context.route(@url_match, method(:handle))
  context.once(Events::BrowserContext::Close, method(:dispose))
end

def add_page_route(page)

def add_page_route(page)
  page.route(@url_match, method(:handle))
  page.once(Events::Page::Close, method(:dispose))
end

def dispose

def dispose
  @local_utils.async_har_close(@har_id)
end

def handle(route, request)

def handle(route, request)
se = @local_utils.har_lookup(
id: @har_id,
 request.url,
od: request.method,
ers: request.headers_array,
_data: request.post_data_buffer,
avigation_request: request.navigation_request?,
esponse['action']
redirect'
rect_url = response['redirectURL']
 "pw:api HAR: #{request.url} redirected to #{redirect_url}" if @debug
e.redirect_navigation_request(redirect_url)
fulfill'
e.fulfill(
atus: response['status'],
aders: response['headers'].map { |header| [header['name'], header['value']] }.to_h,
dy: Base64.strict_decode64(response['body']),
port the error, but fall through to the default handler.
esponse['action'] == 'error'
ts "pw:api HAR: #{response['message']} redirected to #{redirect_url}" if @debug
not_found_action == 'abort'
ute.abort

ute.fallback

def initialize(local_utils:, har_id:, not_found_action:, url_match: nil)

Parameters:
  • url_match (String||Regexp|nil) --
  • not_found_action (String) -- 'abort' or 'fallback'
  • har_id (String) --
  • local_utils (LocalUtils) --
def initialize(local_utils:, har_id:, not_found_action:,  url_match: nil)
  unless ['abort', 'fallback'].include?(not_found_action)
    raise ArgumentError.new("not_found_action must be either 'abort' or 'fallback'. '#{not_found_action}' is specified.")
  end
  @local_utils = local_utils
  @har_id = har_id
  @not_found_action = not_found_action
  @url_match = url_match || '**/*'
  @debug = ENV['DEBUG'].to_s == 'true' || ENV['DEBUG'].to_s == '1'
end