Home > front end >  How to add „From” request header in Firefox-Selenium?
How to add „From” request header in Firefox-Selenium?

Time:11-11

I’m looking for a way to add the “From” request header to disclose an email address of the requesting user. I am using Selenium with Firefox, alternatively I can switch to PhantomJS or Chrome.

It could be some preference to set in selenium.webdriver.FirefoxProfile. I checked Firefox’s about:config documentation, but can’t find any indication how to implement this header. Any help is appreciated especially that it is difficult to google this issue given the name of the header.

CodePudding user response:

Still haven’t found an interface how to do this with Selenium. There is however a workaround with intercepting the request using selenium-wire:

from seleniumwire import webdriver

def from_request_header_interceptor(request):
    del request.headers['From']
    request.headers['From'] = '[email protected]'

driver = webdriver.Firefox(**kwargs)
driver.request_interceptor = from_request_header_interceptor
driver.get('https://www.httpbin.org/headers')

The httpbin outputs i.a. headers “From”: “[email protected]. Seems to work.

  • Related