Skip to content

Electron: Session #32

@xwcoder

Description

@xwcoder

Electron: Session

Used to manage browser sessions, cookies, cache, proxy settings, etc.

  • Access the session of existing pages by using the session property of WebContents.

    const { BrowserWindow } = require('electron')
    
    const win = new BrowserWindow({ width: 800, height: 600 })
    win.loadURL('http://github.com')
    
    const ses = win.webContents.session
    console.log(ses.getUserAgent())
  • Access the default session object of the app by using the defaultSession property of session module.

    const { session } = require('electron')
    console.log(ses.defaultSession)
  • session.fromPartition(partition[, options])

    • Code illustrator

      const { session } = require('electron')
      const ses = session.fromPartition('persist:name')
      console.log(ses.getUserAgent())
    • Return a session instance from partition string. If there is an existing Session with the same partition, it will be returned, otherwise a new Session instance will be created.

    • If partition starts with persist:, the page will use a persistent session available to all pages in the app with the same partition.

    • If there is no persist: prefix, the page will use an in-memory session.

    • If the partition is empty, the default session of the app will be returned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions