selenium-wire icon indicating copy to clipboard operation
selenium-wire copied to clipboard

Doesn't work offline despite having a catch-all request interceptor

Open jmetz opened this issue 2 years ago • 0 comments

Sample code

With internet disabled, run:

def interceptor(request):
    # Intercept all requests
    request.create_response(
        status_code=200,
        headers={'Content-Type': 'text/html'},  # Optional headers dictionary
        body='<html>Hello World!</html>'  # Optional body
    )


# Create a new instance of the Chrome driver
driver = webdriver.Chrome()

driver.request_interceptor = interceptor

# Go to the Google home page
driver.get('https://www.google.com')

# Access requests via the `requests` attribute
for request in driver.requests:
    if request.response:
        print(
            request.url,
            request.response.status_code,
            request.response.headers['Content-Type']
        )

Expected behaviour

When using a "catch-all" mock, I would expect there to be no outbound requests, thus permitting use offline. This should then print the response created in the interceptor eg:

image

Actual behaviour

As the name resolution fails, we get:

image

Is it possible to prevent this lookup from happening also, thus allowing offline use?

jmetz avatar Aug 03 '22 12:08 jmetz