Camera PWA/Browser: Cancel lead to Uncaught (in promise): undefined
I'm submitting a: [X] bug report
Current behavior:
When I cancel the camera popup in the browser I land on the following error:
Error: Uncaught (in promise): undefined at c (http://localhost:8100/build/polyfills.js:3:19752) at http://localhost:8100/build/polyfills.js:3:19174 at rejected (http://localhost:8100/build/main.js:167:89) at t.invoke (http://localhost:8100/build/polyfills.js:3:14976) at Object.onInvoke (http://localhost:8100/build/vendor.js:5134:33) at t.invoke (http://localhost:8100/build/polyfills.js:3:14916) at r.run (http://localhost:8100/build/polyfills.js:3:10143) at http://localhost:8100/build/polyfills.js:3:20242 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660) at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5125:33)
Screenshots
Code
Same as in the documentation https://capacitor.ionicframework.com/docs/apis/camera
If you don't take a photo the call rejects, so you need to wrap getPhoto in a try/catch
thx, sorry for having opened the issue then @mlynch
I'm trying it on iOS and when I cancel the photo nothing happens.
I've tried
public async takePicture(): Promise<string> {
try {
const image: CameraPhoto = await Camera.getPhoto({
quality: 90,
allowEditing: true,
correctOrientation: true,
resultType: CameraResultType.Uri,
source: CameraSource.Camera
});
return this._IMAGE = image.webPath;
} catch (e) {
console.log('no photo');
}
}
and
public async takePicture(): Promise<string> {
const image: CameraPhoto = await Camera.getPhoto({
quality: 90,
allowEditing: true,
correctOrientation: true,
resultType: CameraResultType.Uri,
source: CameraSource.Camera
}).catch((e) => {
console.log('catch cameraphoto');
throw new Error(e);
});
return this._IMAGE = image.webPath;
}
always looking at Xcode for logs but nothing when I cancel the camera.
Problem solved. https://stackoverflow.com/questions/52352608/capacitor-trying-to-catch-the-cancel-on-camera shows that that feature was missing and should be released soon.
Next time you can create a new issue as this one was for PWA, not for iOS and I would have missed it if it wasn't for your SO question.