I coded two demo websites as follows (both written in NextJS):
-
Website 1: I coded an interval counter that increments every 1 second.
-
Website 2: I used the MediaRecorder API (described in the WebKit documentation: https://webkit.org/blog/11353/mediarecorder-api/).
In the ondataavailable function, I periodically send a blob (once every 1 second) to my server. In the backend, I coded a POST API to upload this blob.
I noticed that with website 1, the interval doesn't work when I run Safari in the background, even on iOS and iPadOS. However, website 2 works, meaning it still calls my API normally (I tried running Safari in the background for about 1-2 hours and it worked).
So, does this mean Apple allows native APIs like MediaRecorder and its callbacks to run in the background?