Search code examples
python-3.xseleniumfirefoxwebdrivergeckodriver

Is it possible to script python3 selenium to automatically disable CSP for geckodriver?


I need to disable CSP for that I can do that manually by opening Firefox() web driver, going to about:config, and disabling: security.CSP.enable.

I am new to selenium, have coded all the stuff I need to just I need to automate disabling of CSP, I don't know much about marionette, capabilities, and other details. I just want to automate the disabling of CSP. Is it possible? Is it possible by doing some capabilities changes or by doing: driver.get('about:config'); some code or by adding another extension? There may be other solutions like downloading geckodriver with no CSP, which I cant find, or maybe even compiling geckodriver with no CSP if its open source.

I cant use chromium for some reason, so I need to work with geckodriver in Linux.


Solution

  • This is the ugliest way, building from source code. Steps:

    • Download source of Firefox: Firefox Source. Then, unzip it.
    • cd/Mozilla-central-83bf4fd3b1fb/testing/geckodriver/src/ and edit prefs.rs with your favourite editor. At end write this:
    // Disable CSP
    ("security.csp.enable", Pref::new(false)),
    
    • Build geckodriver using cargo or mach. I used cargo build

    • Load it using:

    webdriver.Firefox(executable_path='./mozilla-central-83bf4fd3b1fb/testing/geckodriver/target/debug/geckodriver')
    

    Finding docs and going through the source code and editing was quite painful as I don't know Rust. Here's the docs: Building Docs