For invalidating the session upon browser close, use below script in your portal harness script files. so that it will prompt each time you close the browser like below.
Use below script in your portal harness scripts&styles by creating or updating new js file.
<script type="text/javascript">
window.addEventListener('beforeunload', function (e) {
// here you can call the logoff functionality or whatever your want
e.returnValue = '';
});
</script>
can you use the browser beforeunload event in your Pega portal harness JavaScript. Add this script in the portal’s Scripts and Styles section or in a JS file loaded by the harness. In that event, call your logout or session invalidation logic, then set e.returnValue = '' so the browser shows its standard leave-page warning. This makes Pega react when the user tries to close the browser or tab. The warning message text is controlled by the browser, not by Pega. With this setup, the session is handled at the moment the browser is being closed.