Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
used in pushManager.Subscribe to correctly encode the key to a Uint8Array
function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding)
.replace(/\-/g, '+')
.replace(/_/g, '/')
;
const rawData = window.atob(base64);
return Uint8Array.from([...rawData].map((char) => char.charCodeAt(0)));
}
@mauricoder

This comment has been minimized.

Copy link

@mauricoder mauricoder commented Jun 15, 2018

Saved my day! Thanks! :)

@bithavoc

This comment has been minimized.

Copy link

@bithavoc bithavoc commented Dec 17, 2018

beautiful

@msjahun

This comment has been minimized.

Copy link

@msjahun msjahun commented Jan 11, 2019

Thank you!

@kannanhassouna

This comment has been minimized.

Copy link

@kannanhassouna kannanhassouna commented May 15, 2019

thanks

@tscpp

This comment has been minimized.

Copy link

@tscpp tscpp commented Jul 22, 2019

thanks

@lilfish

This comment has been minimized.

Copy link

@lilfish lilfish commented Nov 8, 2019

Saved my life!

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