Chrome's Notification API requires some additional information

I've been experimenting with the code from this demo link:

https://davidwalsh.name/demo/notifications-api.php

The demo mentioned above functions perfectly on Chrome, Firefox, and Edge browsers.

I utilized the demo to create an .aspx page by simply copying and pasting the source. I only inserted a <Form..> </Form> to make it work in an .aspx page. After uploading to godaddy, it works flawlessly in Firefox and Edge, but encounters errors in Chrome.

Could anyone suggest any reasons why it might not work in Chrome when hosted on godaddy? Despite not being proficient in Javascript, I can't seem to identify any issues.

Would the absence of SSL on my site prevent notifications from functioning properly? Researching this topic has led me down irrelevant paths.

Thank you,

Update: My .aspx page performs well on localhost in Chrome (IIS Express), as well as in Firefox and Edge. The issue arises only upon deployment to godaddy. Chrome does not prompt for notification permissions when accessing the site on godaddy. Even manually adding the URL to the notification settings doesn't resolve the problem.

-=-=-

One more thing to add. It's difficult to find relevant information online due to similar keywords used in push notifications and web notifications. I'm focusing on web notifications, and came across this statement:

Also, web notification works with both non-SSL and SSL websites.

This contradicts my assumption...unless it's outdated.

Here is the essential code snippet that functions everywhere except where it's most crucial:

Show a Notification

<script type="text/javascript">
        function showNotification() {
            if(window.Notification) {
                Notification.requestPermission(function(status) { 
                    console.log('Status: ', status); 
                    var n = new Notification('Title', { body: 'I am the body text!' }); 
                });
            }
            else {
                alert('Your browser doesn\'t support notifications.');
            }
        }
    </script>   

Answer №1

Correct! To enable push notifications in Google Chrome, you need to use https:// or localhost://.

To bypass Chrome's security measures for local development, you can run Chrome with the

unsafely-treat-insecure-origin-as-secure
option.

open -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
     --args \
     --user-data-dir=$HOME \
     --unsafely-treat-insecure-origin-as-secure=http://your-insecure-domain.dev \

Answer №2

After thorough testing, it appears that the issue lies with SSL. Although many sources claim that "Web Notifications" do not require SSL (as opposed to Push Notifications), I came across a different explanation on a stackoverflow post:

The Notification API will only function properly when accessed from localhost, 127.0.0.1, or through HTTPS due to security reasons. This is because it stores a service worker file in the browser which could be vulnerable to hacking if not encrypted via SSL. Therefore, SSL certificates are necessary for live websites, while local development can be done without SSL.

The demo script works fine on localhost (using IIS Express), but not on IIS with an IP address like 192.168.x.x.

This limitation is frustrating, especially considering that Firefox and Edge allow it to work without SSL.

It's also challenging to find information online since most search results focus on Push Notifications rather than Web Notifications, leading to limited resources on this topic.

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

Unfortunately, we encountered an AJAX error while trying to access data from the website datatables.net. You can find

I'm currently working on adding data to a datatables.net datatable using a JSON response, following the example provided here. To achieve this, I am making use of an AJAX call to fetch a JSON response from a database. After obtaining the data, I uti ...

Angular - Execute function every 30 seconds while considering the duration of the function execution

In my Angular 7 application, I am utilizing RxJS to handle asynchronous operations. My goal is to retrieve a list of items from an API endpoint every 30 seconds. However, there are times when the request may take longer than expected, and I want to ensure ...

I need to figure out a way to validate form data dynamically as the number of fields constantly changes. My form data is being sent via Ajax

Click validation is desired. It is requested that before transmitting data, the validate function should be executed. If there is an empty field, a message should be displayed and the data should not be sent to the PHP file. In case there are no empty fi ...

Why am I getting the error in react-dom.development.js related to my index.js file?

Upon checking the console, the following message is displayed: react-dom.development.js:86 Warning: ReactDOM.render is no longer supported in React 18. Please use createRoot instead. Until you transition to the new API, your application will behave as if i ...

UI not getting updated due to synchronous jQuery ajax call

I am currently facing an issue with my synchronous ajax call executed in a loop. Despite trying to update the UI before each ajax call and on the done callback method, the UI does not update until all ajax calls have been completed. Below is my code snip ...

The connection between MongoClient and Express has been established successfully, however, an error occcurred: TypeError: Cannot read the property 'collection' of null

I am currently working with the MongoClient instead of mongoose, but I am facing an issue where I can't seem to set a new collection in my routes file. db/index.js const {MongoClient} = require('mongodb'); const MONGO_DB_NAME = 'mooo ...

The jQuery library triggers an error that can only be resolved by refreshing the

I am currently experiencing an issue with my form (form links are provided below, specifically referring to form1). The problem arises when I include jquery.js, as it fails to load the doAjax and getIP functions that are contained in a separate js file nam ...

Tips for saving a document in a table without using the _id field

I want to save the employee object without the _id attribute, just the "employee" attribute as shown below: "employee" :[ { "name" : "leila", "idemployee" : ObjectId("59319505efa50b137477a1f4"), ...

The polygon array feature is not functioning as expected in the Google Maps API

I'm currently facing an issue with a code that is supposed to draw polygons from an array in the Google Maps API, but unfortunately, it doesn't seem to be working as expected. <!DOCTYPE html> <html> <head> <script src ...

What could be causing webpack to struggle in locating the loader?

Check out my package.json: { "name": "redux-todo", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "start": "webpack-dev-server" }, "devDependencies": { "babel": "^6.5.2", "babel-loader": "^6.2.5", "bab ...

Switching back and forth between celsius and fahrenheit using jQuery (my mistake in the code)

I am currently using Ajax to interact with the openweather API. Everything seems to be functioning correctly except for one issue. My goal is to create a button that toggles between displaying temperature in Celsius and Fahrenheit. When I click the button ...

Cross-Origin Resource Sharing is enabled yet I am still encountering the error message: "The origin has been blocked by CORS policy because no 'Access-Control-Allow-Origin' header is present."

I am facing a CORS error whenever I try to redirect the browser from the backend. Despite using the CORS package in the backend, it seems like it is not functioning as expected. Below is the code snippet from the client-side: useEffect(() => { async ...

Using JSON objects effectively in MVC4, including parsing them seamlessly!

I am struggling with understanding how to effectively utilize JSON objects within MVC and the correct way to pass them from Controller, to View, to Jscript. I am also unsure if I am correctly parsing the JSON objects at the appropriate places... Within m ...

Encountering difficulties while using JavaScript to complete a form due to issues with loading the DOM

Currently, I am attempting to automate the completion of a multi-page form using JavaScript. Below is the script that I am utilizing: // Page 1 document.getElementById("NextButton").click(); // Page 2 completion(document.getElementById("Rec ...

Properties of objects changing dynamically

<div id="bach">Bach</div> <div id="show">about composer</div> $(window).load(function(){ bach = {"bdate": 1685, "bplace": "Eisenach, Germany"} $("div").click(function(){ $("#show").text(this.id['bdate']); // ...

Tips for breaking down a collection of objects and nested arrays into distinct arrays containing individual pieces of data

I have a list of objects structured like this: [ { alert_count: 3, alert_level: {value: 0, label: "ignore"}, count_dates: (3) ["2021-04-21T14:36:02.446Z", "2021-04-21T14:36:12.039Z", "2021-04-21T14:37:04.495Z"], sound_type: {_id: "606331d ...

The Rails/Ajax function is not replacing the DIV as expected, but rather nesting a new DIV inside

Struggling to dynamically update a DIV using AJAX after a form submission. Here is the content of my partial _inline.html.erb: <div class="large-12 columns" id="inline_posts"> <% @posts.each do |post| %> <div class="row"> <div ...

Issue with IE7 when using JQuery to repopulate a <ul> unordered list: new elements showing up under previously hidden elements

Within this javascript snippet, I am utilizing the code below to clear out a list of countries within a <ul> element and then repopulate it (with a slight animation using jQuery's hide() function). The functionality works smoothly in Chrome and ...

Positioning the comments box on Facebook platform allows users to

Need assistance, I recently integrated the Facebook comments box into my Arabic website, but I am facing an issue where the position of the box keeps moving to the left. Here is an example of my website: Could someone please suggest a solution to fix the ...

What's preventing the mobx @computed value from being used?

Issue: The computed value is not updating accordingly when the observable it is referencing goes through a change. import {observable,computed,action} from 'mobx'; export default class anObject { // THESE WRITTEN CHARACTERISTICS ARE COMPUL ...