Is there any way to capture/intercept the temporary re-directs using playwright and add custom headers?
I have a page in which the initial request will give response with status code 303 that will redirect to multiple redirects with status code 307 (Temporary redirects). I need to intercept one the temporary redirect and add an header and send the request. Is there any way to handle this?
#HTTPHeaders #PythonPlaywright
I tried using handle_request() to capture the redirects like below:
def handle_request(route, request):
# Update the headers if match_string is present in url
if "match_string" in request.url:
print(f"Modifying headers for redirected request: {request.url}")
headers = {**request.headers, 'custom_header_1': 'value_!23'}
route.continue_(headers=headers)
else:
# Continue the request without modification
route.continue_()
But, does not capture the temporary redirects which is initiated from another redirect. So unable to add headers using handle_request.
1