Widely Supported
Facebook Messenger Extension close method is the most compatible way to do it. On mobile it closes the webview, on desktop it will close the tab (webviews open in new tabs on desktop messenger).
First, whitelist your domain to be able to use Messenger Extensions, use the access token for your app. Use the page_access_token you generated for your bot.
curl -X POST -H "Content-Type: application/json" -d '{
"whitelisted_domains":[
"https://petersfancyapparel.com"
]
}' "https://graph.facebook.com/v2.6/me/messenger_profile?access_token=PAGE_ACCESS_TOKEN"
Load the Messenger SDK on your webview page with the video
<script>
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.com/en_US/messenger.Extensions.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'Messenger'));
</script>
Then add an event listener to the video element to call the close browser function
<video src="video.ogv" id="myVideo">
video not supported
</video>
<script type='text/javascript'>
document.getElementById('myVideo').addEventListener('ended',myHandler,false);
function myHandler(e) {
MessengerExtensions.requestCloseBrowser(function success() {
}, function error(err) {
});
}
</script>
iOS Only
Quick and dirty ios only way is to do a redirect to to https://www.messenger.com/closeWindow/?image_url=IMAGE_URL&display_text=DISPLAY_TEXT
which shows the specified image and text briefly before the window closes. Docs on this
For that you would do
window.replace('https://www.messenger.com/closeWindow/?image_url=IMAGE_URL&display_text=DISPLAY_TEXT')