electron 清除所有cookie记录

时间:2020-06-08 14:43:08   收藏:0   阅读:503
const {session} = require(‘electron‘);

// 查询所有 cookies。删除。
    session.defaultSession.cookies.get({})
    .then((cookies) => {
      cookies.forEach(cookie => {
        let url = ‘‘; 
        // get prefix, like https://www. 
        url += cookie.secure ? ‘https://‘ : ‘http://‘; 
        url += cookie.domain.charAt(0) === ‘.‘ ? ‘www‘ : ‘‘; 
        // append domain and path 
        url += cookie.domain; 
        url += cookie.path; 
        session.defaultSession.cookies.remove(url, cookie.name, (error) => { 
          if (error) console.log(`error removing cookie ${cookie.name}`, error); 
        }); 
      })
    }).catch((error) => {
      console.log(error)
    })

  

来自:http://cn.voidcc.com/question/p-ewqoesfv-cw.html

原文:https://www.cnblogs.com/sxdjy/p/13065559.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!