Last active
December 17, 2021 02:06
-
-
Save ygweric/5023b90bb0a60ab4c28c549dd87809c2 to your computer and use it in GitHub Desktop.
清除chrome所有的cookie,localStorage,sessionStorge, clear all cookie, localStorage, sessioinStorage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const clearCookieAndStorage = () => { | |
// clear cookies | |
(function () { | |
setTimeout(() => { | |
var cookies = document.cookie.split("; "); | |
for (var c = 0; c < cookies.length; c++) { | |
var d = window.location.hostname.split("."); | |
while (d.length > 0) { | |
var cookieBase = encodeURIComponent(cookies[c].split(";")[0].split("=")[0]) + '=; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=' + d.join('.') + ' ;path='; | |
var p = location.pathname.split('/'); | |
document.cookie = cookieBase + '/'; | |
while (p.length > 0) { | |
document.cookie = cookieBase + p.join('/'); | |
p.pop(); | |
}; | |
d.shift(); | |
} | |
} | |
}, 0); | |
setTimeout(() => { | |
var cookies = document.cookie.split(";"); | |
for (var i = 0; i < cookies.length; i++) { | |
var cookie = cookies[i]; | |
var eqPos = cookie.indexOf("="); | |
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie; | |
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; | |
} | |
}, 0); | |
})(); | |
// --- clear storage | |
localStorage.clear(); | |
sessionStorage.clear(); | |
console.log(`--------- cookie and storage cleared`) | |
} | |
clearCookieAndStorage() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment