
How to get the Picture In Picture close button event in JavaScript
There's an event for leaving picture-in-picture, rather than the button click itself.
video.addEventListener('leavepictureinpicture', doSomething);
https://developer.mozilla.org/en-US/docs/Web/API/HTMLVideoElement/leavepictureinpicture_event