最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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 "--disable-csp" which dose not exist according to my search results.
  2. a setting for webdriver/protractor to do so.

I could not find any solution but to setup a proxy that filters the header.

any ideas?

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 "--disable-csp" which dose not exist according to my search results.
  2. a setting for webdriver/protractor to do so.

I could not find any solution but to setup a proxy that filters the header.

any ideas?

Share Improve this question asked Nov 14, 2018 at 15:59 Adi DarachiAdi Darachi 2,1751 gold badge16 silver badges31 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

currently there are no native option but you can disable CSP using extension.

Step:

  1. Download extension Disable Content-Security-Policy
  2. Save it as .zip, because it need modification to enable "disable CSP" at start
  3. extract the file or if using Winrar double click file background.js to edit
  4. change var isCSPDisabled = false; to true
  5. save change.

code

chrome_options = Options()
chrome_options.add_extension('path/to/disableCSP.zip') # or disableCSP.xpi
driver = webdriver.Chrome(chrome_options=chrome_options)

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./")

source: Load chrome extension using selenium

发布评论

评论列表(0)

  1. 暂无评论