About automatic login, the answer is yes. I have a simple script that logs me into some sites automatically. But I don't use chrome.windows listener for that. I have a script that basically does this -
$("#username").val("username"); $("#password").val("mysupersecretpassword"); $("#login-form").submit();
My manifest.json specifies that this as a content script for the site that I want to run it on.
{ "name" : "Login Script", ... // "content_scripts": [ { "matches": [ "http://127.0.0.1/phpmyadmin/" ], // Running it here on my local phpmyadmin "js": ["js/jquery.min.js", "js/login.js"] //load jquery since I use it here, and the login script } ], ... // edited for brevity }
This isn't an ideal solution, in terms of storing passwords within the script in my case. But this is one way of doing the login.
Regarding log-out, you can probably create a logout function in your background page, and call that from the windows.onRemoved event. I'm not sure a script running on the page would be allowed to continue running when it is being closed. Calling the background page, allows the background page code to log you out, while the window itself closes.
HTH