Relaxing Chrome's CSP while running tests (webdriver) (Content-Security-policy)

后端 未结 2 1906
醉话见心
醉话见心 2021-01-16 17:48

I\'m trying to relax Chrome\'s CSP while running a test using proctractor (webdriver, chromedriver).

So the solution can be either

  1. a flag like \"--dis
2条回答
  •  旧时难觅i
    2021-01-16 18:19

    I update @ewwink's answer

    1. Go to the website of the extension developer Disable CSP github
    2. Download the extension code in zip format
    3. Unzip and modify the background.js file with:
        var isCSPDisabled = function (tabId) {
            return true; // disabledTabIds.includes(tabId);
        };
    
    1. In Chrome go to: ... -> Tools -> Extensions -> Active the Developer mode -> Pack extension ... Choose the modified folder as the root directory -> Leave the field: private key file blank -> This will create a .crx file next to the extension folder, and a private key as if it were the developer
    2. Use the generated crx file like this:
        from selenium import webdriver
        from selenium.webdriver.chrome.options import Options
    
        chrome_options = Options()
        chrome_options.add_extension("/path/to/chrome-csp-disable-master.crx")
        driver = webdriver.Chrome(executable_path="/path/to/chromedriver", options=chrome_options)
        driver.get("https://www.google.com/")
    

    source: Load chrome extension using selenium

提交回复
热议问题