Disable “Clear cookies and site data when you quit Chromium” programatically

余生长醉 提交于 2021-02-08 09:06:11

问题


I see this "Clear cookies and site data when you quit Chromium" on Chrome's and Chromium's settings.

I would like to change disable it when starting browser with Selenium. I didn't find any chrome option, nor any chrome argument that would help.

I have check this code of Chromium, where are all the prefs but I didn't find anything regarding to cookies, site data, quit, exit, cleanup.

Also not finding any relevant on the chromium arguments: https://peter.sh/experiments/chromium-command-line-switches


回答1:


Try using chrome capabilities:

from selenium import webdriver

caps = webdriver.DesiredCapabilities.CHROME.copy()
caps['deleteDataPostSession'] = False
driver = webdriver.Chrome(desired_capabilities=caps)

driver.get("http://www.google.com")

This toggles the setting to off me when i kick it off with python:


[update]

In the comments i was asked how i found this - answer is i looked at the source and followed the white rabbit..

I started with the text for the settings. I searched for Clear cookies and site data

In this file: settings_google_chrome_strings.grdp i got this hit:

  <!-- Cookie Settings Page -->
  <message name="IDS_SETTINGS_SITE_SETTINGS_DELETE_DATA_POST_SESSION" desc="Label for the checkbox that allows the user to automatically delete their cookies and site data at the end of the browser session.">
    Clear cookies and site data when you quit Chrome
  </message>

I could see that wasn't quite right. So i searched for the name of the setting, and that got one hit in file: md_settings_localized_strings_provider.cc

      {"deleteDataPostSession",
       IDS_SETTINGS_SITE_SETTINGS_DELETE_DATA_POST_SESSION},

That looked about right for what i usually stick into capabilities... All that was left was to test it - and it worked.




回答2:


RichEdwards helped me to solve it. In .NET I used the following code:

chromeOptions.AddUserProfilePreference("deleteDataPostSession", false);

The flag will still be enabled, but the cookies are present in the cookies store on the profile path. On the profile path's Default folder's Preferences file, I could see the change:

"deleteDataPostSession":false

What is not clear yet from me, where can you search for the proper preference name like deleteDataPostSession? I couldn't find anything like this in the chromium code.



来源:https://stackoverflow.com/questions/63300851/disable-clear-cookies-and-site-data-when-you-quit-chromium-programatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!