Code Monkey home page Code Monkey logo

Comments (6)

Antoinebr avatar Antoinebr commented on July 21, 2024 64

If needed here's the function

/**
 * urlBase64ToUint8Array
 * 
 * @param {string} base64String a public vavid key
 */
function urlBase64ToUint8Array(base64String) {
    var padding = '='.repeat((4 - base64String.length % 4) % 4);
    var base64 = (base64String + padding)
        .replace(/\-/g, '+')
        .replace(/_/g, '/');

    var rawData = window.atob(base64);
    var outputArray = new Uint8Array(rawData.length);

    for (var i = 0; i < rawData.length; ++i) {
        outputArray[i] = rawData.charCodeAt(i);
    }
    return outputArray;
}

from web-push-codelab.

atb00ker avatar atb00ker commented on July 21, 2024 19

(Considering this issue is still relevent)urlBase64ToUint8Array is mentioned on this page: https://developers.google.com/web/fundamentals/push-notifications/subscribing-a-user

from web-push-codelab.

tomasdev avatar tomasdev commented on July 21, 2024 13

By the way the function is defined at https://github.com/GoogleChrome/push-notifications/blob/master/app/scripts/main.js

from web-push-codelab.

Dygear avatar Dygear commented on July 21, 2024 3

The real question. Why is this not built into browsers?

from web-push-codelab.

riophae avatar riophae commented on July 21, 2024 1

I've also found this: https://www.npmjs.com/package/urlb64touint8array

from web-push-codelab.

gauntface avatar gauntface commented on July 21, 2024

Where is urlBase64ToUint8Array mentioned in the tutorial?

from web-push-codelab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.