Notification access is consistently denied

In my coding work, I rely on Notification.permission to determine if the browser supports notifications or not. Here's a snippet of how I handle Notification.permission in my script:

// Verify browser notification support
if (!("Notification" in window)) {
    alert("This browser does not support desktop notification");
}
var prm = Notification.permission;
if (prm == 'default' || prm == 'denied') {
    console.log("Permission denied or default");
} else {
    console.log("Permission granted");
}

While this code operates smoothly on my localhost, in a production environment, it consistently displays a 'denied' status. My browser notification settings are configured to 'always allow on this site'. https://i.sstatic.net/cMuAQ.png I am currently stumped by this issue and unable to pinpoint the cause.

Answer №1

It's quite simple, the message reads: [Deprecation] The Notification API should not be used from insecure origins anymore. It is advisable to transition your application to a secure origin, such as HTTPS. Refer to Google's recommendations for more information. (anonymous) @ ?message=unique-identifier=123:25 ?message=unique-identifier=123:26 denied your lint should resemble something like this: [linkExample1][2] - for index.html or [linkExampe2][2]


You can find the link here it won't function online but you can execute it on a local server by creating an html file and running it under the HTTPS protocol, then choosing the Allow option in your URL: https://i.sstatic.net/jvU6z.png

Just a heads up, avoid using private (incognito mode) for this exercise - for security purposes push notifications are disabled in private or incognito mode

    let dnperm = document.getElementById('dnperm');
    let dntrigger = document.getElementById('dntrigger');

    dnperm.addEventListener('click', function(e){
        e.preventDefault();

        if(!window.Notification){
            alert("Notification not supported!");
        }else{
            Notification.requestPermission().then(function(permission) {
                console.log(permission);
                if(permission === 'denied'){
                    alert('You Have Denied Notification!');
                }else if(permission === 'granted'){
                    alert('You Have Granted notification.');
                }
            })
        }
    });

    // simulate

    dntrigger.addEventListener('click', function(e){
        let notify;

        e.preventDefault();

        console.log(Notification.permission);

        if(Notification.permission === 'default'){
            alert('Please allow notification before doing this');
        }else {
            notify = new Notification('New Message From Romzik', {
                body: 'How are you today? Is it really is a lovely day.',
                icon: 'img/msg-icon.png',
                tag: 'unique-identifier=123' // msg-id
            });

            notify.onclick = function (ev) {
                console.log(this);
                window.location = '?message=' + this.tag;
            }
        }


    })
<body>
<a href="" id="dnperm">Request permission</a>
<a href="" id="dntrigger">Trigger</a>
</body>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The information submitted through the form is not displaying on the console after being gathered using the post method in Express

When attempting to add products using a form on the admin page, the data (including an image file) is not being displayed in the console as expected. Instead, the following message appears: "{} POST /admin/add-product - - ms - -" Below is th ...

The dual-file upload feature of the jQuery ajaxForm plugin

After extensive searching online, I have yet to find an answer to my problem. The issue at hand is that when using the ajaxForm malsup plugin, it submits my files twice. HTML: <form id="gallery" enctype="multipart/form-data" action="/upload-gallery.p ...

Implementing Conditional Loops with $.each in AngularJS

I am working with an array called vm.settings.tab_permissions. Within this array, I need to check if the role is equal to vm.heading and replace it with vm.data. If the role is not equal, I want to push vm.data to vm.settings.tab. However, my current cod ...

Access the file by using the local absolute path for reading or downloading

I need to access and read a file located at D:/home/abc.pdf on my local drive using AngularJs. var path = "D:/home/abc.pdf"; var doc = document.createElement("a"); doc.href = path; doc.download = path; doc.click(); window.URL.revokeObjectURL(path); Howev ...

An intriguing inquiry regarding HTML form intricacies

Looking to enhance the source code by adding a new column to display Client Mobile, Client Office Telephone, and Client E-mail in a separate popup PHP page. My attempt involved adding a form and submit button to generate the new column. However, pressing ...

NodeJS domain error handling failing to catch ReferenceError exceptions

I'm currently facing some challenges with domains in NodeJS. I've set up middleware functions to wrap every call in my web application within a domain in order to capture errors, process them, and return informative error messages. While this se ...

Having trouble with ReactJS updating the state in the correct format using moment?

In my ReactJS project, I am using a datepicker feature. However, I have encountered an issue where the state is not being updated with the selected date value after formatting it using moment.js. const [selectedDates, setSelectedDates] = useState([]) ...

What is causing my grayscale function to only impact part of the canvas?

As a beginner programmer, I have been experimenting with creating a grayscale function in JavaScript for practice. This is the code I have come up with: <canvas width='400' height='400'></canvas> <script> var can ...

Understanding the visibility scope in JavaScript's object-oriented programming

I have the following code snippet: function A() { this.AFunction = function() { var b = new B(); b.BFunction(); } } function B() { this.BFunction = function() { // some code $.ajax({ url: url suc ...

Make sure to select the checkbox using a protractor only if it hasn't been checked already

I am attempting to retrieve a list of checkboxes using CSS and only click on a checkbox if it is not already selected. I have successfully obtained the list, but I am encountering an issue when trying to validate whether or not the element is selected. Ca ...

Error in executing Javascript function

Below is a Javascript function I created for expanding and collapsing content: function showAns(inp){ var hide="#hideAns"+inp; var show="#showAns"+inp; var ansdiv ="#ans"+inp; $(hide).click(function(){ $(ansdi ...

The CSS for the ajax call functions correctly on desktop devices but is not displaying properly on mobile devices

My ajax call is facing an issue where the CSS classes for a loader and overlay are only being applied in desktop view, not mobile view. I am unsure of what mistake I may be making. Can someone help me resolve this problem? Here is the ajax call: function ...

Improving Zen Coding to integrate with JavaScript files on Sublime Text2

Sublime Text2 is hands down my go-to editor, except for one minor hiccup - the Zen Coding plugin only works with CSS and HTML files. There are plenty of times where I'd love to use Zen Coding with JavaScript or other file types, like incorporating HTM ...

Exploring the Concept of Dependency Injection in Angular 2

Below is a code snippet showcasing Angular 2/Typescript integration: @Component({ ... : ... providers: [MyService] }) export class MyComponent{ constructor(private _myService : MyService){ } someFunction(){ this._mySer ...

Unable to bring in the Firebase Firestore Colletion

When working on my next app, I encountered an error while trying to call a Firestore Collection. The specific error message that appeared when I ran the app was: FirebaseError: Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicat ...

Sharing a boolean state between two pages using Material UI components

One challenge I've been facing is passing a boolean useState value between two pages. I found a helpful solution on this Stack Overflow thread: How to call useState from another Page? The main goal here is to display a success alert on a separate pag ...

Set up ExpressJS to utilize port 3000 for the server

I am working on an app where the backend is currently running on localhost:8000, but I need it to run on port 3000. Specifically, I am using an express server for this example. How can I configure it to run on the desired port? Below is my current server. ...

Sending a POST request from a React application to a Node server and processing the JSON

I'm a beginner in React and I'm working on understanding how everything comes together. Is there a way to switch the rendering component for another one after receiving a status 200 response from a node server? For instance, if I make a POST re ...

Issue with large date changes causing MUI DatePicker to freeze

The MUI DatePicker, whether from Labs or X, was functioning perfectly. However, I am now facing an issue where it hangs when trying to change the date by ten years. It appears that the code gets stuck in an endless loop, yet there are no errors displayed i ...

Received an unexpected GET request while attempting to modify an HTML attribute

After clicking a button in my HTML file, a function is called from a separate file. Here is the code for that function: function getRandomVideoLink(){ //AJAX request to /random-video console.log("ajax request"); var xhttp = new XMLHttpRequest( ...