Chrome Permissions

1,018 views
Skip to first unread message

Kira Corbin

unread,
Feb 27, 2020, 12:28:17 AM2/27/20
to Native-Client-Discuss

I'm want to create a pop-up message to the user to allow permissions for NFC reader to be read from a webpage.

I have Javascript code written and linked to the html, but no pop-up is activated. 

I'm not getting the pop up to fire, I want to get it working on all browsers and smart phones.

These are my console log errors.
Uncaught ReferenceError: NDEFReader is not defined at permissions.js:73
permissions.js:17 Uncaught (in promise) TypeError: Failed to execute 'query' on 'Permissions': GenericSensorExtraClasses flag is not enabled.
    at checkPermission (permissions.js:17)
    at permissions.js:36
/client/client.ed17b3c8.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
permissions.js:45 [Deprecation] getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.
requestGeolocation @ permissions.js:45

Here is my code:
// make permissions request work
// state of permissions: granted, denied, prompt

// Status of a permission
if ('permissions' in navigator) {
    var logTarget = document.getElementById('logTarget');

    function handleChange(permissionNamenewState) {
        var timeBadge = new Date().toTimeString().split(' ')[0];
        var newStateInfo = document.createElement('p');
        newStateInfo.innerHTML = '' + timeBadge + ' State of ' + permissionName + ' permission status changed to ' + newState + '.';
        logTarget.appendChild(newStateInfo);
    }

    function checkPermission(permissionNamedescriptor) {
        try {
            navigator.permissions.query(Object.assign({ name: permissionName }, descriptor))
                .then(function (permission) {
                    document.getElementById(permissionName + '-status').innerHTML = permission.state;
                    permission.addEventListener('change'function (e) {
                        document.getElementById(permissionName + '-status').innerHTML = permission.state;
                        handleChange(permissionNamepermission.state);
                    });
                });
        } catch (e) {
        }
    }

    checkPermission('geolocation');
    checkPermission('notifications');
    checkPermission('push', { userVisibleOnly: true });
    checkPermission('midi', { sysex: true });
    checkPermission('camera');
    checkPermission('microphone');
    checkPermission('background-sync');
    checkPermission('ambient-light-sensor');
    checkPermission('accelerometer');
    checkPermission('gyroscope');
    checkPermission('magnetometer');

    var noop = function () { };
    navigator.getUserMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);

    function requestGeolocation() {
        navigator.geolocation.getCurrentPosition(noop);
    }

    function requestNotifications() {
        Notification.requestPermission();
    }

    function requestPush() {
        navigator.serviceWorker.getRegistration()
            .then(function (serviceWorkerRegistration) {
                serviceWorkerRegistration.pushManager.subscribe();
            });
    }

    function requestMidi() {
        navigator.requestMIDIAccess({ sysex: true });
    }

    function requestCamera() {
        navigator.getUserMedia({ video: true }, noopnoop)
    }

    function requestMicrophone() {
        navigator.getUserMedia({ audio: true }, noopnoop)
    }
}

// API glimpse
const reader = new NDEFReader()
// Creates an object used for NDEF readings.
    reader.scan(options)
//   Returns a Promise resolved if starting NFC scan was successful.
    reader.addEventListener('reading'listener)
// An event fired when a new reading is available.
    reader.addEventListener('error'listener)
// An event fired when an error happened during reading.
const writer = new NDEFWriter()
// Creates an object used for NDEF writings.
    writer.write(messageoptions)
//   Returns a Promise resolved if writing the message(String, ArrayBuffer or NDEF record) with options was successful.







Derek Schuff

unread,
Feb 27, 2020, 11:13:47 AM2/27/20
to native-cli...@googlegroups.com
Hi Kira,
This mailing list is for discussion of Native Client specifically, so this post about general JS and permissions is off-topic (and you aren't really reaching the right set of experts in any case). Offhand I don't know of any other mailing lists that are meant for webNFC, but there is the W3C community group (https://www.w3.org/community/web-nfc/) and of course the obvious.
-Derek

--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-di...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/native-client-discuss/ab693fb8-8a8b-4707-8ef5-7d02bf186dc5%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages