cordova-plugin-camera icon indicating copy to clipboard operation
cordova-plugin-camera copied to clipboard

Cannot fire on browser

Open juancresc opened this issue 7 years ago • 9 comments

A very simple picture capture snippet is not working on browser (chrome Version 71.0.3578.98) or firefox. I'm using a mac.

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    console.log(navigator.camera);
    document.getElementById("cameraTakePicture").addEventListener("click", cameraTakePicture);
}

function cameraTakePicture() {
    navigator.camera.getPicture(onSuccess, onFail, {
        quality: 50,
        destinationType: Camera.DestinationType.DATA_URL
    });

    function onSuccess(imageData) {
        var image = document.getElementById('myImage');
        image.src = "data:image/jpeg;base64," + imageData;
    }

    function onFail(message) {
        alert('Failed because: ' + message);
    }
}

Error in chrome: Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided. at successCallback (CameraProxy.js:105)

Error in Firefox: navigator.mozGetUserMedia ha sido reemplazado por navigator.mediaDevices.getUserMedia CameraProxy.js:112:8 [Mostrar/ocultar detalles del mensaje.] TypeError: Argument 1 is not valid for any of the 1-argument overloads of URL.createObjectURL. CameraProxy.js:105:21 successCallback http://localhost:8000/plugins/cordova-plugin-camera/src/browser/CameraProxy.js:105:21

juancresc avatar Dec 23 '18 14:12 juancresc

Same issue

M-a-c avatar Dec 31 '18 04:12 M-a-c

@juancrescente

Ok so this is actually an issue that has been resolved but is not part of a release the last release was on Apr 12, ON May 24 in https://github.com/apache/cordova-plugin-camera/commit/5163d3846558c70753af0d232bec762f337f2c66#diff-6856bdfe878c6f9fa378adaa7fc4e488 it was fixed. However there was no version for this fix. so it appears broken.

How to fix: If you are using ionic, or importing this package. you can put the repo (thought it will be the most current repo updates, and not locked to a version anymore*) Because it is not a VERSION, you will have to remove all the build 'plugins' and re run your project so it rebuilds the plugin list. remove the versioned cordova-plugin-camera from the package.json and then npm install https://github.com/apache/cordova-plugin-camera

M-a-c avatar Dec 31 '18 06:12 M-a-c

Any ideas when this is going to be released? I have the same problem :)

muuvmuuv avatar Jan 05 '19 18:01 muuvmuuv

@muuvmuuv No idea when its going to be fixed but the work around will allow you to dev for now. you can always roll back to a release version instead of the git repo code

M-a-c avatar Jan 05 '19 22:01 M-a-c

@M-a-c thanks, I needed to do one additional step ionic cordova plugin remove cordova-plugin-camera && ionic cordova plugin add https://github.com/apache/cordova-plugin-camera to get it working in firefox. Before I have not seen the camera overlay.

muuvmuuv avatar Jan 06 '19 10:01 muuvmuuv

The following code snippet works perfectly fine for me. I'm using Cordova 9.0.0 and[email protected] on Chromium and macOS. I strongly believe this should work on other browsers too.

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        console.log(navigator.camera);
        const openCameraButton = document.getElementById('open-camera');
        openCameraButton.addEventListener('click', this.cameraTakePicture);
    },

    cameraTakePicture: function() {
        navigator.camera.getPicture(onSuccess, onFail, {
            quality: 50,
            destinationType: Camera.DestinationType.DATA_URL
        });

        function onSuccess(imageData) {
            var image = document.getElementById('image-id');
            image.src = "data:image/jpeg;base64," + imageData;
        }

        function onFail(message) {
            alert('Failed because: ' + message);
        }
    }
};

app.initialize();

GedasGa avatar Apr 02 '19 06:04 GedasGa

Wish this was fixed. This plugin could be mistaken for dead based on its releases.

TDola avatar Jul 09 '19 16:07 TDola

My standard dependancy came in version 2.x, where I encountered the same issue. For me it was sufficient to reinstall it via cordova plugin remove camera and cordova plugin add cordova-plugin-camera --save

JamesCullum avatar Aug 13 '19 19:08 JamesCullum

The following code snippet works perfectly fine for me. I'm using Cordova 9.0.0 and[email protected] on Chromium and macOS. I strongly believe this should work on other browsers too.

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        console.log(navigator.camera);
        const openCameraButton = document.getElementById('open-camera');
        openCameraButton.addEventListener('click', this.cameraTakePicture);
    },

    cameraTakePicture: function() {
        navigator.camera.getPicture(onSuccess, onFail, {
            quality: 50,
            destinationType: Camera.DestinationType.DATA_URL
        });

        function onSuccess(imageData) {
            var image = document.getElementById('image-id');
            image.src = "data:image/jpeg;base64," + imageData;
        }

        function onFail(message) {
            alert('Failed because: ' + message);
        }
    }
};

app.initialize();

thankyou, its work

andibastian avatar Nov 03 '20 14:11 andibastian

This was fixed in 4.1.0

jcesarmobile avatar Sep 29 '22 11:09 jcesarmobile