Skip to content
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

Cannot fire on browser #399

Closed
juancresc opened this issue Dec 23, 2018 · 10 comments
Closed

Cannot fire on browser #399

juancresc opened this issue Dec 23, 2018 · 10 comments

Comments

@juancresc
Copy link

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

@M-a-c
Copy link

M-a-c commented Dec 31, 2018

Same issue

@M-a-c
Copy link

M-a-c commented Dec 31, 2018

@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 5163d38#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

@muuvmuuv
Copy link

muuvmuuv commented Jan 5, 2019

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

@M-a-c
Copy link

M-a-c commented Jan 5, 2019

@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

@muuvmuuv
Copy link

muuvmuuv commented Jan 6, 2019

@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.

@GedasGa
Copy link
Contributor

GedasGa commented Apr 2, 2019

The following code snippet works perfectly fine for me. I'm using Cordova 9.0.0 andcordova-plugin-camera@4.0.3 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();

@TDola
Copy link

TDola commented Jul 9, 2019

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

@JamesCullum
Copy link

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

@andibastian
Copy link

The following code snippet works perfectly fine for me. I'm using Cordova 9.0.0 andcordova-plugin-camera@4.0.3 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

@jcesarmobile
Copy link
Member

This was fixed in 4.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants