'Error while generating FCM token using django
This is error that i am getting in my javascript console:
An error occurred while retrieving token. DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
at https://www.gstatic.com/firebasejs/8.6.3/firebase-messaging.js:1:25606
I am trying to send push notification from firebase but getting error. any one plz help me. i am trying to generate FCM token in javascript console but getting error
here is my index.html file where i am getting import error
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://www.gstatic.com/firebasejs/8.6.3/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.3/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.3/firebase-messaging.js"></script>
{% comment %} <script src="/static/js/firebase-messaging-sw.js"> {% endcomment %}
<script>
var firebaseConfig = {
apiKey: "*****",
authDomain: "*****",
databaseURL: "*****",
projectId: "*****",
storageBucket: "*****",
messagingSenderId: "*****",
appId: "*****",
measurementId: "*****"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
const messaging = firebase.messaging();
console.log(messaging.getToken())
messaging.getToken({ vapidKey: '*****' }).then((currentToken) => {
if (currentToken) {
console.log(currentToken)
} else {
console.log('No registration token available. Request permission to generate one.');
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
});
messaging
.requestPermission()
.then(function () {
console.log("Notification permission granted.");
return messaging.getToken()
})
.catch(function (err) {
console.log("Unable to get permission to notify.", err);
});
messaging.onMessage((payload) => {
console.log('Message received. ', payload);
});
</script>
</head>
<body>
</body>
</html>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|