How to manipulate cookies in BrowserWindow?


#1

Hi all!

I’m looking for something like node-webkit’s window.cookies -> https://github.com/rogerwang/node-webkit/blob/master/src/api/window_bindings.js#L31-L80

I couldn’t find anything relevant on https://github.com/atom/atom-shell/blob/master/atom/browser/api/lib/browser-window.coffee or anywhere in the source code.

Any tips? Is this not implemented or am I missing something?


#2

Same here.

I can see them:

    window.webContents.on('did-finish-load', function() {
        this.executeJavaScript("alert(document.cookie)");
    });

But I cant get them, this function passes back ‘null’ if I try ‘return document.cookie’


#3

The main issue with executeJavascript or injecting a script before the page loads is that you can’t delete HttpOnly cookies or manipulate cookies across domains like you can with the node-webkit cookies api.


#4

I’m trying to read the cookies after the page loads on the ‘did-finish-load’ event, executeJavascript can access them using document.cookie but not pass them back.

    var BrowserWindow = require('browser-window');
    var window = new BrowserWindow({
        "width": 900, 
        "height": 450, 
        "show": false, 
        "resizable": false, 
        "skip-taskbar": true
    });
    window.on('closed', function() {
      window = null;
    });
    window.loadUrl("www.google.com");
    window.show();
    window.webContents.on('did-finish-load', function() {
        var document.cookie
        executeJavaScript("alert(document.cookie)");
       // how to get cookies ????
    });

Bit frustrating!


#5

Electron v0.28.3 introduces a cookies API. Check out the browser-window documentation and look for WebContents.session.cookies.


#6

Does this process get called in the rendering process or main? Thanks for the help!