Registering Serviceworker in Laravel - javascript

I'm using pushpad (from pushpad.xyz) and followed the 3 initial steps to setup this SDK with my Laravel 5.5 Project.
But as soon as I visit a test view it just cannot find and register the Serviceworker.js
i tried placing it all over the place, almost in every folder now. So i know this is vaguely described but if you take a quick look at the Docs from pushpad you know what I mean.
Moreover, when i manually try to open it i get a 404.
also getting 404 when i try to import it via from the https:// link where its located
when i copy its content and use it in a script tag i also get a 404.
im quite clueless as how to proceed
A bad HTTP response code (404) was received when fetching the script.
Failed to load resource: net::ERR_INVALID_RESPONSE
push-test:1 Uncaught (in promise) TypeError: Failed to register a
ServiceWorker: A bad HTTP response code (404) was received when fetching the
script.

You need to make sure that you have a service-worker.js file in the root directory of your website.
You can verify the installation by typing https://example.com/service-worker.js in your browser.

Related

Bad HTTPS cert: "TypeError: Failed to execute 'compile' on 'WebAssembly': HTTP status code is not ok" in Webworker

I'm trying to run Webassembly inside a Webworker
I can load heavyLifting.wasm perfectly fine the traditional way (aka not in a webworker) but trying to load it inside a webworker runs into warnings (not errors actually). Here's how I loaded it:
// worker.js
self.importScripts('heavyLifting.js');
And the warning:
wasm streaming compile failed: TypeError: Failed to execute 'compile' on 'WebAssembly': HTTP status code is not ok
From what I gather, it finds the file - but I assume it has something to do with it not being HTTPS.
I actually haven't tried serving it through HTTPS yet (because locally serving HTTPS has become a lot more difficult for some reason). However, does anyone have any knowledge that might save me a few more hours of banging my head against the wall? Did I forget some setting or config? Why would a webworker be extra picky about what wasm it serves (because as I mentioned, I'm able to serve up my wasm fine as a regular script)
Update:
It wasn't an HTTPS error - it had to do with importScript().
worker.js
js/
heavyLifting.js // glue code
heavyLifting.wasm
This was all fixed by moving worker.js down into the js folder.
I immediately ran in to the following error:
'Uncaught (in promise) TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.'
It turns out the node package http-server doesn't serve wasm properly, but the python3 http.server does.

Failed to Load Resource In Production but Not Locally

I am working on a Django project and I have it deployed on pythonanywhere.com. In my project, I am using Django Jsignature which works fine on my local machine. In production, however, when I load the particular template, I get this error in my console - 'myurl' portion is not the real url.
https://myurl.com/static/js/jSignature.min.js net::ERR_ABORTED 404 (Not Found)```
So I don't get this locally, but do in Production. Can anyone suggest for me where to start on this? I'm not even really sure where to begin, it's my first time deploying anything.
EDIT
you can see the details of django jsignature here: https://pypi.org/project/django-jsignature/
the {{form.media}} should load this script.
UPDATE 2
This is no longer working locally either. Here are the error in my console.
Uncaught SyntaxError: Invalid or unexpected token jSignature.min.js:70
Uncaught TypeError:
$(...).jSignature is not a function

Failed to register service-worker TypeError - Expo Error

I have recently encountered the following error when I npm run start my expo app;
Uncaught DOMException: Failed to execute 'importScripts' on
'WorkerGlobalScope': The script at
'http://localhost:19006/service-worker.js' failed to load.
at http://localhost:19006/expo-service-worker.js:93:6
The script has an unsupported MIME type ('text/html').
This error has never occurred until of late, in which I pulled down the app source code onto a new machine, so I have a incline that this could be the issue.
When I used to Service Worker debugger using Chrome Dev Tools, the error flags up on the last line of the code in expo-service-worker.js (see screenshot)
I have literally done nothing different, I have seen other solutions stating I should modify some of the service-worker registration code, but this sits uncomfortable with me being as this is an automatic process when running the app.
The app boots-up fine, but it has trouble connecting to the external api linked to the app, because the service worker is not being registered.
One my other machine, the app launches, registers a service worker and connects to the api fine, just not on the machine currently.
Any suggestions?
Thanks.
A service worker importScripts() script must be served with a valid javascript content-type header. See:
https://w3c.github.io/ServiceWorker/#dfn-bad-import-script-response
In this case you are getting a content-type of text/html. One common way this can happen is if the server returns a 404 for the resource URL passed to importScripts.

For the ajax url shows 404 on the AWS tomcat log

I was using MVN install deploy my code on the AWS tomcat. I did this by directly open the AWSname:8080/manager/html and upload the WAR file(I am not sure if it is the correct way). The server can load the index.html successfully as my expectation and shows page on the front-end, but error went to call AJAX, which is in Javascript file, it always return 404. The servlet's url pattern will be like this
AJAX
Login Servlet
I tested everything fine on my localhost:8080, but in the AWS tomcat, the log showed like this.
Tomcat Log
I've never met such a case before, could somebody give me some useful suggestions on the possible solutions?
from your description it is not clear if you have multiple apps/war/containers/servers.
From your message you have a UI, which seems not to be bundled into your war file. To check in this case use these steps to check your setups
Add a index.html to your root in the war file and test if you can access it locally.
if this works, deploy on AWS and try to access the same path on AWS.
if the page is showing, your context is defined well on AWS. So you have an issue with your URL mappings
But if it does not show, you have a URL problem (wrong URL on AWS)

Failed to load resource error after using a bundler

I was finally able to import and use axios by installing a bundler (parcel bundler). I configured it, but now when I run the server I receive an "Failed to load resource: the server responded with a status of 404 (Not Found)" error for localhost/:1, which takes me to the first line of index.html in the inspect window after I click it.
Some pictures to clarify:
This is strange because the website loads and is visible (which wouldn't have been possible if it couldn't load index.html as that is what is being shown) so maybe I am not getting right what this error even means.

Categories