Thursday, November 24, 2022
HomeiOS Developmentjavascript - ship video "onpagehide" for IOS Safari

javascript – ship video “onpagehide” for IOS Safari


Problem

I’ve a MediaRecorder video of as much as 400 KB that I must ship to the server.
I would like to have the ability to additionally ship the video when somebody exits the web page.
My working code for Chrome/Edge:

window.onbeforeunload = (e) => {
    e.preventDefault();
    attempt { 
        self.recorder.cease(); 
    } 
    catch (err) { 
        console.log(err); 
    }
    return null;
}

Nevertheless window.onbeforeunload would not work on Safari, so I resorted to window.onpagehide:

window.onpagehide = (e) => {
    e.preventDefault();
    attempt { 
        self.recorder.cease(); 
    } 
    catch (err) { 
        console.log(err); 
    }
    return null;
}

Nevertheless window.onpagehide would not permit async capabilities.
Which means that the recorder.cease() and the axios.publish inside it aren’t working.
I managed to make the cease work by making a syncronous operate for it, however I can not discover another for axios.publish.

Query

What axios.publish different ought to I take advantage of for this situation?
Or how can I make axios.publish run in a onpagehide name?

What I attempted

navigator.sendBeacon
It appeared fairly promising, however it has a restrict of 64KB, so I could not depend on it.

fetch
I attempted the next:

fetch('my-site-url', {
    methodology: 'POST',
    physique: formData
});

And bought the next:

Fetch API can not load my-site-url attributable to entry management checks.

However I do not assume it is a CORS associated concern…

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments