Mobile Chrome not recognizing service worker registration

I am currently working on implementing push notifications for my domain across desktop and mobile devices. I have successfully set up push notifications on desktop, but I am facing issues with Chrome for Android.

Despite having tested the code on powerful devices such as the OnePlus 3 and Huawei Mate 9, I am unable to register the service worker on Chrome for Android. Strangely, I do receive web notifications on these devices, so it is a perplexing issue.

Here is the code snippet that I am using:

<script type="text/javascript">
if('serviceWorker' in navigator && 'PushManager' in window) {
    alert('best');
    window.addEventListener('load', function() {
       navigator.serviceWorker.register('/sw.js').then(function(registration) {
          alert('test');
       });
    });
}
</script>

The first alert indicates that the browser supports service workers and push notifications. However, the second alert does not pop up on mobile Chrome, even though it works perfectly fine on desktop Chrome. I am confused about what could be causing this discrepancy.

This code is implemented on a page named test.php

Any insights or suggestions would be greatly appreciated!

Answer №1

Make sure to edit the file path to include the dot "./sw.js". If you omit the dot, it will be interpreted as being located in the root of your server.

Answer №2

Instead of preceding the file name with ./, try using just the file name sw.js. I encountered similar problems and found that simply changing this worked for me. You can also check out this link for more help.

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

Unable to style Backbone View with CSS

Recently started diving into the world of Backbone, and it seems like I might be missing a key concept here. In my View object, there's a snippet of code that's puzzling me... First off, I can't figure out why the CSS change in the highli ...

Validation check: Ensure that the value does not match any other field

Looking for a method to compare two fields and only validate them if they are not equal. This is the approach I've tried, but it's not working: yup .number() .required() .notOneOf( [FormField.houseHoldMembers as any], &ap ...

How come repeating a call to an animation function in three js results in skipping certain animations?

I am trying to create a repeated animation sequence involving a sphere moving and then a rectangle, followed by displaying the number of times it has been repeated in a div called expected_output. However, I'm encountering an issue where the animation ...

Improving the performance of my function

Is there a way to optimize this code for efficiency? Net-beans is flagging it for having too many lines in the functions. It also suggests creating a new function where the if statement currently resides. Can someone assist me in refactoring this code an ...

I can't seem to locate the "pause on exceptions" feature in Firefox 47

Although the Firefox documentation mentions "Pause on Exceptions" as a debugger option, it seems to be missing from the Settings panel in Firefox 47. Where could I possibly locate it now? UPDATE: This is how my settings panel looks like. https://i.sstati ...

Importing JWT in ES6SyntaxCreating ES6 imports

I'm currently developing a nodeJS web application and utilizing JWT for authentication. My code is all written in ES6 modules, so I wanted to import JWT the same way. However, it seems that the package does not fully support this method yet. Since I&a ...

Tips for modifying HTML attributes in AngularJS

I am looking to modify an attribute of a div using AngularJS. While I am familiar with how to do this in jQuery, I am not sure how to achieve it in Angular. Here is the HTML code: <div ng-app="test"> <div ng-controller="cont"> < ...

"Webpack error: Including a comma within a string leads to a syntax problem when bund

I'm attempting to merge this file into my main JS. var constants = { height: 600, width: 400, default_bezier = "[ { \"startPoint\" : [51.6503017608354,203.464445873753], \"endPoint\" : [-52.41285540263849,202.372456432 ...

Guide to creating an intricate formula using the keyup event

Just starting out with coding and I need help making this formula work. GPro = 31 * ((Cr / 8.4)-1.5) * (kA-0.2) * kG I have an online calculator set up to update automatically when the user inputs data (on keyup event). The site has three formulas - Crum ...

Is it possible for the activity and service to operate within the same process in an application?

Query: When running an application, do the Activity and Service operate in the same process or different processes? My Response: They run in the same process. Follow-up Question: How is it possible for the Activity and Service to run simultaneously if th ...

Having trouble with MUI auto import suggestions in my Next.js 13 project on VS Code

I'm currently developing a project using Next.js 13 and have installed MUI. However, I am encountering an issue where VS Code is not providing auto imports from the @mui/material library, as shown in the attached screenshot. https://i.stack.imgur.com ...

Passport.js does not provide authentication for server-side asynchronous requests

Recently, I configured Passport.js with the local-strategy on my express server. Interestingly, when I am logged in and send an asynchronous request within NextJS's getInitialProps, it allows the GET request through client-side rendering but not serv ...

Solving the issue of redundant parentheses using JavaScript's regex

When I attempt to replace ...('2073')... with ....('2074')... I end up with ...(('2074'))... and I am perplexed as to why. Check out this javascript snippet: var sGroupIdentifier = "2073"; var sSelectedGroupTR = "... onclick ...

Developing a fresh instance in JavaScript

Currently, I am working with a JSON object that I'm required to use in my project. const template = require('../../../../assets/jsons/article-tpl.json'); Next, I need to iterate through an array and utilize this object to generate a new te ...

I encountered an error while working with the angular factories in my project

Encountering an error despite injecting the factory into the controller. Any help or suggestions to resolve this issue would be much appreciated. Error: [$injector:unpr] http://errors.angularjs.org/1.3.16/$injector/unpr?p0=<div ng-view="" class="ng-s ...

Issues with submitting data using jQuery AJAX PUT request

I have a PHP script with the following content: if ($_SERVER['REQUEST_METHOD'] === 'PUT') { echo '{ "response": "' . $_REQUEST['id'] . '" }'; } Now, I am trying to use jQuery to make an AJAX request t ...

Issue encountered while constructing NextJS application; error was encountered during the pre-rendering of the

I encountered an issue while trying to deploy my app; specifically, I faced an error during the project building process. info - Loaded env from /Users/furkanulker/Desktop/Projects/dev-project/.env info - Skipping validation of types info - Creating a ...

Overcome the issue of 'Parsing Error: Kindly verify your selector. (line XX)' in Javascript/AWQL

Hello there! Just to clarify, I am not a developer and my coding skills are limited to basic HTML. Your patience is greatly appreciated ...

What is the best way to align grid elements vertically instead of horizontally on mobile devices using JQuery Mobile?

I've created a basic JQuery Mobile website with a grid containing four horizontally aligned blocks, each with text and a button. While it displays well on desktop browsers, the blocks appear cramped when viewed on my Android Galaxy phone in landscape ...

List of options displayed in a dropdown/selectbox with a menu tree

Would it be possible to incorporate a treemenu within a dropdown/selectbox? My categories are structured like this: <ul id="example"> <li>Category1 <ul> <li><a href="http://www.autisticcuckoo.net">Category1 subcat ...