BAT清理Edge,Firefox, Chrome的cache cookie等,不改变保存的账号历史记录

测试用到清理浏览器缓存等数据,每次打开要登录测试website。所以写了这个脚本,清理cache, cookie和网站自动保存的数据(特别是在website上search,filter,改动column位置之类)而不动账号信息:

@echo off

echo 正在关闭浏览器Edge, Firefox 和 Chrome(Cloud开头的窗口)...
::关掉edge和Firefox浏览器
taskkill /IM msedge.exe /IM Firefox.exe 

::关掉chrome浏览器中标题以Cloud开头的进程,标题名第一位必须写,后面可以*来匹配
taskkill /IM chrome.exe /FI "windowtitle eq Cloud*"


echo 正在清理Edge...
::清理Edge浏览器的chche, cookie, session和local storage,并使用edge打开website。其中local storage会存储一些设置参数,下次打开读取local storage然后打开跟上次关闭前一样的设置。
set edge_cacheFolder=%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Cache
::set edge_codeCacheFolder=%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Code Cache
set edge_sessionFolder=%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Sessions
::set edge_sessionStorageFolder=%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Session Storage
::set edge_syncDataFolder=%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Sync Data
::set edge_serviceWokerCacheStorage=%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Service Worker\CacheStorage
set edge_localStorage=%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Local Storage
set edge_cookieFile=%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Cookies
::set edge_webData=%userprofile%\AppData\Local\Microsoft\Edge\User Data\Default\Web Data

rd /s /q "%edge_cacheFolder%"
rd /s /q "%edge_sessionFolder%"
rd /s /q "%edge_localStorage%"
del "%edge_cookieFile%"
start msedge https://www.baidu.com/ --start-maximized


echo 正在清理Firefox...
::参考http://www.nirsoft.net/utils/mzcv.html的工具,找到firefox的cache,cookie路径。或者在firefox里面输入about:profiles,能看到默认的profiles路径,分为root和local两个
::set firefox_cacheFolder=%userprofile%\AppData\Local\Mozilla\Firefox\Profiles\*.default-release\cache2
::set firefox_cookieFile=%userprofile%\AppData\Roaming\Mozilla\Firefox\Profiles\*-release\cookies.sqlite
set firefox_localProfileDir=%userprofile%\AppData\Local\Mozilla\Firefox\Profiles\
set firefox_roamingProfileDir=%userprofile%\AppData\Roaming\Mozilla\Firefox\Profiles\
for /f "delims=" %%a in ('dir /ad /b %firefox_localProfileDir%') do (
	echo %%a|findstr /m "release" > null && set firefox_profileName=%%a
)
rd /s /q "%firefox_localProfileDir%\%firefox_profileName%\cache2"
rd /s /q "%firefox_roamingProfileDir%\%firefox_profileName%\storage"
del "%firefox_roamingProfileDir%\%firefox_profileName%\cookies*"
del "%firefox_roamingProfileDir%\%firefox_profileName%\webappsstore.sqlite"
start firefox https://www.baidu.com/ --start-maximized


echo 正在清理Chrome...
::清理Chrome浏览器的chche, cookie, session和local storage,并使用chrome打开website。
set chrome_cacheFolder=C:\test\Default\Cache
set chrome_localStorage=C:\test\Default\Local Storage
set chrome_sessionFolder=C:\test\Default\Sessions
set chrome_cookieFile=C:\test\Default\Cookies
::set chrome_cookie=%userprofile%\AppData\Local\Google\Chrome\User Data\Default\

rd /s /q "%chrome_cacheFolder%"
rd /s /q "%chrome_localStorage%"
rd /s /q "%chrome_sessionFolder%"
del "%chrome_cookieFile%"
::使用--user-data-dir="C:\test"参数,将chrome文件都保存单独目录,避免影响到我另外开的工作用的chrome浏览器
start chrome --user-data-dir="C:\test" --start-maximized https://www.baidu.com/


pause

上一篇:静态内部类实现单例


下一篇:修改VMOptions文件的堆内存后发现idea无法打开的问题