capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

Camera PWA/Browser: Cancel lead to Uncaught (in promise): undefined

Open peterpeterparker opened this issue 8 years ago • 5 comments

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

capture d ecran 2018-06-22 a 17 17 03

Code

Same as in the documentation https://capacitor.ionicframework.com/docs/apis/camera

peterpeterparker avatar Jun 22 '18 15:06 peterpeterparker

If you don't take a photo the call rejects, so you need to wrap getPhoto in a try/catch

mlynch avatar Jun 22 '18 15:06 mlynch

thx, sorry for having opened the issue then @mlynch

peterpeterparker avatar Jun 22 '18 15:06 peterpeterparker

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.

ix-xerri avatar Sep 16 '18 15:09 ix-xerri

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.

cc-xerri avatar Sep 19 '18 12:09 cc-xerri

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.

jcesarmobile avatar Sep 19 '18 12:09 jcesarmobile