-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Camera not working in PWA after app returns from background in iOS #298
Comments
It seems there's a dependency to https://cdn.jsdelivr.net/npm/[email protected]/dist/jsQR.min.js |
I am using PWA in the same way, but when I use it in the background on iOS, I can't re-use the camera and have no choice but to close it and start over again. I have this I am incorporating this into the html |
I doubt that it is the reason. The devices are online the whole time. It just occurs when moving the app into background and back forward. @0tsu0i0ihajime the error is still not resolved and also the reason has not be found yet. |
If I do this on a non-cellular model iPad in an environment with Wi-Fi turned off, the camera will stop and not come back on when I move it to the background and then undo it when using PWA. |
On an iPhone 12 I was testing on, the PWA app would get in a state where the video element of the reader would refuse to start at all after going into the background and coming back. My eventual workaround had two parts: In Additionally, in the
I was starting to wonder about brushing off my Swift skills, such as they are, and going native at about this point (which presumably is exactly what Apple wants me to do!) |
I have the same problem, using iOS 16.4 on an iPhone 13. After reopening the app from the background, the camera remains black. The red camera indicator appears in the top left corner and then immediately disappears again. navigator.mediaDevices.getUserMedia() returns successfully… |
This issue has been marked as stale. If there is no further activity it will be closed. |
Posting to keep the issue open - same issue on iPhone 14. Same issue exactly as Jannis033. |
Apparently, when QrcodeStream is used in an iOS PWA and goes into the background, the stream on the video element is stopped. When the user returns, the stream is not restarted automatically. To fix this we try keep track whether the page/app is in the foreground and stop/start the stream when this state changes. Incidentally, this commit makes the demo page is now PWA installable to make this testable. Closes #298
Apparently, when QrcodeStream is used in an iOS PWA and goes into the background, the stream on the video element is stopped. When the user returns, the stream is not restarted automatically. To fix this we try keep track whether the page/app is in the foreground and stop/start the stream when this state changes. Incidentally, this commit makes the demo page is now PWA installable to make this testable. Closes #298
I deployed a PWA installable version of the demo page (without fix) but I can't reproduce the issue on iOS 16. https://deploy-preview-351--vue-qrcode-reader.netlify.app/ Can someone confirm whether this is reproducible on the demo page. |
Just tried on iPhone 14 with iOS 16.5.1 and worked initially. However when I closed the app and reopened it, it did not work - as per the issue. For information it worked fine on Pixel 6 / Chrome. |
Apparently, when QrcodeStream is used in an iOS PWA and goes into the background, the stream on the video element is stopped. When the user returns, the stream is not restarted automatically. To fix this we try keep track whether the page/app is in the foreground and stop/start the stream when this state changes. Incidentally, this commit makes the demo page PWA installable to make this fix testable. Closes #298
Ah I see, I can reproduce it too now. You really have to close the app. I thought putting it into background already has this effect. Also thanks @mrrrk. The hints are very helpful. Sorry for the long wait. Looks like the issue corresponds to this Webktit bug. In the thread they are saying a fix has been merged literally last week. But I guess that will only benefit (far?) future iOS versions. |
On iOS devices in PWA mode, QrcodeStream works initially, but after killing and restarting the PWA, all video elements fail to display camera streams. Looks like this is related to this WebKit issue: https://bugs.webkit.org/show_bug.cgi?id=252465 No workarounds at the time of writing. But as suggested in the thread we can put a timeout on the video elements to start loading. That way we can at least detect when the error occurs and throw an error event. Also this commit: 1. Makes the demo page PWA installable to reproduce this problem. 2. Renames the "DecodeAll" demo to "HandleErrors". The demo already is focused on error handling because it renders the error message instead of just printing to the console, which is particularly useful on mobile devices. Renaming the demo emphasizes that and hints user to use this demo for debugging. See #298
On iOS devices in PWA mode, QrcodeStream works initially, but after killing and restarting the PWA, all video elements fail to display camera streams. Looks like this is related to this WebKit issue: https://bugs.webkit.org/show_bug.cgi?id=252465 No workarounds at the time of writing. But as suggested in the thread we can put a timeout on the video elements to start loading. That way we can at least detect when the error occurs and throw an error event. Also this commit: 1. Makes the demo page PWA installable to reproduce this problem. 2. Renames the "DecodeAll" demo to "HandleErrors". The demo already is focused on error handling because it renders the error message instead of just printing to the console, which is particularly useful on mobile devices. Renaming the demo emphasizes that and hints user to use this demo for debugging. See #298
On iOS devices in PWA mode, QrcodeStream works initially, but after killing and restarting the PWA, all video elements fail to display camera streams. Looks like this is related to this WebKit issue: https://bugs.webkit.org/show_bug.cgi?id=252465 No workarounds at the time of writing. But as suggested in the thread we can put a timeout on the video elements to start loading. That way we can at least detect when the error occurs and throw an error event. Also this commit: 1. Makes the demo page PWA installable to reproduce this problem. 2. Renames the "DecodeAll" demo to "HandleErrors". The demo already is focused on error handling because it renders the error message instead of just printing to the console, which is particularly useful on mobile devices. Renaming the demo emphasizes that and hints user to use this demo for debugging. See #298
On iOS devices in PWA mode, QrcodeStream works initially, but after killing and restarting the PWA, all video elements fail to display camera streams. Looks like this is related to this WebKit issue: https://bugs.webkit.org/show_bug.cgi?id=252465 No workarounds at the time of writing. But as suggested in the thread we can put a timeout on the video elements to start loading. That way we can at least detect when the error occurs and throw an error event. Also this commit: 1. Makes the demo page PWA installable to reproduce this problem. 2. Renames the "DecodeAll" demo to "HandleErrors". The demo already is focused on error handling because it renders the error message instead of just printing to the console, which is particularly useful on mobile devices. Renaming the demo emphasizes that and hints user to use this demo for debugging. See #298
Ok, so until someone finds a workaround, I implemented what they suggested in the WebKit issue thread: throw an error when the problem occurs, so at least the application can respond to it. You should be able to do something like this in v5.1.0: <qrcode-stream @error="onError" /> const onError = event => {
if (event.name === "StreamLoadTimeoutError") {
// handle error
}
} Also, check out the corresponding demo. |
So I added the But is there a workaround to restart the camera initialisation or reset it somehow? I already tried a combination of different approaches, but nothing seems to work. If the user closes the PWA once (with swiping it up from the background app panel), the App is broken and needs to be re-installed. This is my current try of a workaround:
|
I also tried a lot of things but nothing worked unfortunately. In the webkit issue thread I linked above, also nobody had a workaround. |
In IOS 17 Beta Public Beta 2 the issue seems to be resolved. I have tried it multiple times with several PWAs and could not reproduce the issue. In IOS 17 Beta 1 the issue was still present for me. |
I also have this issue, so do we need to wait for IOS to update to IOS 17 before this is fixed? |
Yes, I doubt so. But iOS 17 will be released in a few weeks already and if you cannot wait, there are some pretty stable public betas available. |
Since today the scanner exits with the StreamLoadTimeoutError everytime - also when newly started and not activating from the background. I have not changed anything - neither on the web nor on my phone. Same issue on 3 client's phones. I then updated from 16.4.1 to 16.4.2 - when I started the PWA again for the first time on the new system, the camera access worked. But this was the only time it worked - later tests did not work any more. I also found out that the PWA camera access works when the camera app has just been put to background. |
I have tested my PWA on iOS 17.2 and everything works. I hope it will be live soon. |
This issue has been marked as stale. If there is no further activity it will be closed. |
This issue has been marked as stale. If there is no further activity it will be closed. |
Interesting -- at first I was about to report that I'm still running into this issue, and my iPhone 12 is on 17.5.1. At first, the Vue app was fine running in Safari on the phone, but the installed PWA would get the StreamLoadTimeoutError every time. I did try a couple of the workarounds here (camera app backgrounded, etc) but so far nothing has worked. But then I powered the phone off and on, and now it seems to work consistently, no matter what. So far. 🤞 (And the PWA works on the iPad (also running 17.5.1) just fine no matter what. I do get prompted whether to allow the camera each time I launch the app, but that we can live with I think. And interesting I'm not ever getting prompted for camera access on the iPhone) |
ios 17.5.1 ... the error StreamLoadTimeoutError gets thrown randomly when switching between cameras - I don't have a big issue with it as it happens very little, but when it happens I have to refresh the web page to get it running again. (I have a web app in vue3) - is there a way to just do a hard-reset when the error gets thrown? unmounting the component doesn't help either, bit confused as how to handle it inside the app without having to force refresh the entire page. Thank you. |
Hmm, if it gets thrown "randomly" maybe it's a race condition with the timeout. I'll increase the timeout a bit and see if that helps. |
Thank you! Yes it's very "random", I tried to break it on purpose after it appeared the first time ... but suddenly it was fine and I could switch 50 times, then I would refresh and it would throw the error after 3 switches. When it happened I tried to refresh again and follow the exact pattern of switching, suddenly it would work flawlessly. No specific order has proven to be prone to failure.. and I did give it hell in order to give you a better description 😅 but unfortunately, seems random. |
@Asko-Dev reports that the `SteamLoadTimeoutError` seems to be thrown "randomly" on iOS 17.5.1 ( see #298 ). That suggests that there is a race condition with the timeout. Let's try to double the timeout (3s -> 6s) and see if that helps. Side changes: * The ESLint setup is broken somehow and since linting is a pre-commit hook it blocks the committing process. Thus, removing the setup entirely for now. To be fixed later if deemed necessary. * migrate legacy Nix setup to Nix flakes / direnv
Same issue here, still happening in v5.5.7 Info:
|
That's still to be expected unfortunately. No known fix available. |
Maybe you are using basic HTTP?
I generated SSL cert and added it to the project (I use Nuxt: https://nuxt.com/docs/api/nuxt-config#https).
|
I have this error too, but I don't get this error for a long time after restarting the device. I will run my tests again now. |
In my environment (iPhone 15 Pro iOS 18.1.1), the issue has resolved by restarting iPhone. I found it in the thread in webkit. |
Describe the bug
The camera stops working after the PWA returns form background on my 12 mini. The camera also doesn't work at all on an iPhone 13 (see videos below). App works perfectly fine in Safari. PWA also works fine on Android devices.
To Reproduce
Implement this Demo as PWA: https://gruhn.github.io/vue-qrcode-reader/demos/DecodeAll.html#decode-continuously
Screenshots
iPhone 12 mini behaviour
ios.mp4
iPhone 13 behaviour
PWA-QR-2.mp4
Smartphone:
The text was updated successfully, but these errors were encountered: