Testing in Firefox and Safari, I've tried both of the following lines. Each sets the cookie, but neither approach expires the cookie after I've closed (then re-opened) the browser. The browser's cookie info says "test" is set to expire, "At end of session", but it doesn't happen.
There are some similar posts about this (e.g, When does a cookie with expiration time 'At end of session' expire?) but nothing has helped or is about setting the the cookie via JavaScript specifically like I'm doing.
// fails to expire after browser closing
document.cookie = "test=1; expires=0; path=/";
// fails to expire after browser closing
document.cookie = "test=1; path=/";