Electron set cookie

后端 未结 3 1925
终归单人心
终归单人心 2021-01-25 14:11

I am new to electron and converting an web app to desktop application.I am loading pages from file system.Cookies are working if pages are served from web server but when I load

3条回答
  •  遥遥无期
    2021-01-25 14:39

    Follow the documentation to get it done, and use the standard.https://electronjs.org/docs/api/cookies

      const {session} = require('electron')
    
          // Query all cookies.
          session.defaultSession.cookies.get({}, (error, cookies) => {
            console.log(error, cookies)
          })
    
          // Query all cookies associated with a specific url.
          session.defaultSession.cookies.get({url: 'http://www.github.com'}, (error, cookies) => {
            console.log(error, cookies)
          })
    
          // Set a cookie with the given cookie data;
          // may overwrite equivalent cookies if they exist.
          const cookie = {url: 'http://www.github.com', name: 'dummy_name', value: 'dummy'}
          session.defaultSession.cookies.set(cookie, (error) => {
            if (error) console.error(error)
          })
    

提交回复
热议问题