This is fantastic, Thanks so much for jumping in.
I have completed some testing and found the following behavior which is acceptable.
1. If the user interacts with the form after launch (enters data, etc) then if they choose to close the form, the popup will appear giving them the chance to return to the form. If there was no interaction with the form it just closes the page.
When the popup appears it does not include the message as constructed in the code, but instead displays the browsers default message "Leave site" as the example above shows
2. The Submit button appeared to work normally and there was no popup generated at time of original submission or in a User Task action Button selection (Submit, Approve and Reject) including when the form had data changes in the User Task.
3. When the User selects the Save as Draft button, it functions normally, but when the task was closed using the close button, they are presented the Leave Popup
All the best