You can create a coach view and use window's onbeforeunload function , the function will get executed on window close event.
Within function you can trigger the boundary event.
var _this=this;
window.onbeforeunload = function(){
_this.context.trigger()
};
At server side, you can wire the boundary event with a script to (tw.system.currentTask.reassignBackToRole()) to reassign back the task.