Reputation: 21
Maybe someone know how to surfing in Chrome without using browser cache? I run in loop get the pages in the incognito-mode and do not close the browser. But it seems it used cache, because the browser did not close.
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-java")
driver = webdriver.Chrome(chrome_options=chrome_options)
i = 1
while i < 10:
driver.get('https://selenium.com')
browser.quit()
Upvotes: 2
Views: 10032
Reputation: 308
I know that post is old but for those who are in 2020 is looking for solution( all browsers and not only chrome) that can be achieved with BrowserMob(BrowserUP) proxy itself - you can set a rules on requests and responses that will delete headers related to caching mechanisms in browsers( there are lot of them). Below are scripts I use( them might be incomplete so if you found what is missing please let know):
Requests:
curl --location --request POST 'your_proxy_api_host:your_proxy_api_port/proxy/your_proxy_port/filter/request' \
--header 'Content-Type: text/plain' \
--data-raw 'request.headers().remove('\''If-Modified-Since'\'');request.headers().remove('\''If-None-Match'\'');'
Response:
curl --location --request POST '0.0.0.0:8080/proxy/8081/filter/response' \
--header 'Content-Type: text/plain' \
--data-raw 'response.headers().remove('\''Age'\'');response.headers().remove('\''ETag'\'');response.headers().remove('\''Cache-Control'\'');response.headers().remove('\''Expires'\'');response.headers().remove('\''Last-Modified'\'');response.headers().remove('\''Vary'\'');response.headers().add('\''Expires'\'', 0);response.headers().add('\''Cache-Control'\'', '\''private'\'');response.headers().add('\''Cache-Control'\'', '\''no-cache'\'');response.headers().add('\''Cache-Control'\'', '\''no-store'\'');response.headers().add('\''Cache-Control'\'', '\''must-revalidate'\'');response.headers().add('\''Vary'\'', '\''*'\'');'
I work with http 1.1 so I didn't add anything for http 1.0 or http 2.0. Checked on Chrome Edge Safari FF. Also, I use little proxy api( new api of browsermob) - for reference
Upvotes: 0
Reputation: 245
You can also use Chrome with --disable-application-cache argument, which is equivalent to "Private mode"
Upvotes: 0
Reputation: 1015
You should try using the following every time you navigate to a different page.
driver.manage().deleteAllCookies();
or you could just simply browse to the cache page within chrome itself and click the "clear browsing data" button via selenium.
chrome://settings/clearBrowserData
Upvotes: 0