Skip to content

Instantly share code, notes, and snippets.

@ace4gi
Forked from adriancooney/nw-js-cookies.js
Last active October 11, 2019 01:52
Show Gist options
  • Select an option

  • Save ace4gi/5407635f702433c8896ac6cf8f4e194e to your computer and use it in GitHub Desktop.

Select an option

Save ace4gi/5407635f702433c8896ac6cf8f4e194e to your computer and use it in GitHub Desktop.
Quick snippet to display cookie in NW.js (node-webkit) in a sweet console table.
/**
모든 쿠키 확인
*/
require("nw.gui").Window.get().cookies.getAll({}, console.table.bind(console));
/**
쿠키 값 수정
*/
nw.Window.get().cookies.set({
url: "https://aaa",
domain: "aaa",
name: "device-id",
value: "2222",
secure: false,
httpOnly: true,
expirationDate: 1572413761
}, function (resultCookie) {
console.log("resultCookie: " + resultCookie);
});
/**
모든 쿠키 삭제
*/
function removeAllCookies(win) {
win = win || nw.Window.get();
function removeCookie(nwWin, cookie) {
console.log('removing cookie:' + cookie.name + ':' + cookie.domain + cookie.path);
var lurl = "http" + (cookie.secure ? "s" : "") + "://" + cookie.domain + cookie.path;
nwWin.cookies.remove({url: lurl, name: cookie.name},
function (result) {
if (result) {
if (!result.name) {result = result[0];}
console.log('cookie remove callback:' + result.name + '' + result.url);
} else {
console.log('cookie removal failed');
}
}
);
}
win.cookies.getAll({}, function (cookies) {
for (var i = 0; i < cookies.length; i++) {
removeCookie(win, cookies[i]);
}
});
}
removeAllCookies();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment