-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service worker does not successfully serve the manifest's start_url. #4541
Comments
Potentially a case of #2688? |
The project is the in the directory run:
|
Hi, I have encountered the same issue, when using create-react-app, out of the box because the service worker fails to serve the start_url, as you can see in this image: In order to fix this, I've fetched a service worker script from: http://www.manifoldjs.com/ using the Service Worker for offline pages. self.addEventListener("fetch", function(event) {
event.respondWith(
fetch(event.request).catch(function(error) {
console.log(
"[Service Worker] Network request Failed. Serving content from cache: " +
error
);
//Check to see if you have it in the cache
//Return response
//If not in the cache, then return error page
return caches
.open(
"sw-precache-v3-sw-precache-webpack-plugin-https://silent-things.surge.sh"
)
.then(function(cache) {
return cache.match(event.request).then(function(matching) {
var report =
!matching || matching.status == 404
? Promise.reject("no-match")
: matching;
return report;
});
});
})
);
}); Then I use cra-append-sw to append this code to the Create-React-App default Service Worker. Set start_url in manifest to "./index.html" and it passes the audit. Note that the index.html is server anyway, so this might just be a Lighthouse bug. Hope this hopes with the investigation. I have made a repo with the code that should work here: https://github.com/icyJoseph/test-worker/blob/master/src/service-worker.js |
I'm not using CRA, but I've copied whole code concerning SW to my project based on Can you please explain the meaning of Can I copy this code to my register service worker file safely? |
I've navigated to https://silent-things.surge.sh/, used Audit, and get the same |
Hej, That's the name of the cache, aka cacheName, replace it with yours, that string is the url of project I used to test CRA, combined with some CRA defaults. EDIT I have now deployed to https://silent-things.surge.sh I would just like you to say that without this add-on to the CRA service worker, the app does serve index.html in offline mode, it is just lighthouse that flags it. |
Ok, so as I understand, this peace of code has no real value, except making lighthouse to stop false negative warning? |
I could of course be wrong, but yes. There seems to be a false negative. Please refer to:
The blame seems to come from: In line 78, static assessOfflineStartUrl(artifacts, result) {
const hasOfflineStartUrl = artifacts.StartUrl.statusCode === 200;
if (!hasOfflineStartUrl) {
result.failures.push('Service worker does not successfully serve the manifest\'s start_url');
if (artifacts.StartUrl.debugString) result.failures.push(artifacts.StartUrl.debugString);
}
if (artifacts.StartUrl.debugString) {
result.warnings.push(artifacts.StartUrl.debugString);
}
} Hopefully this gives you more insight on to how to fix your problem. For me this is as far as I go to jump over a false negative. |
Yeah I've pretty much given up on fixing this error: When you view my site www.mlamannadev.com from an android device a banner does pop up so I don't know why I'm still getting this error in lighthouse. |
I have the same problem. :-( I am using polymer cli and sw-precache. |
Same here. The banner does pop up on android device but the stupid error makes my Lighthouse has 82 points. |
@stefany93 same thing here... I assume that Google Lighthouse is not their top priority looking at the speed of development and improvement |
@icyJoseph seems to have pinpointed the piece of code responsible for this pretty serious bug #4541 (comment) @patrickhulce @wardpeet @paulirish @karolklp Could one of you review and confirm if he's correct (that it's a false positive) and suggest or implement a fix? It's causing fresh create-react-app projects to fail—as well as fresh Google projects. |
The piece of code that @icyJoseph pinpointed is where the display string is being added to the set of errors but not the cause of the bug. @brendankenny didn't you recently discover something w.r.t manifest parsing that might help here? |
Thanks for the info @patrickhulce and helping move this along. |
The user is prompted to install the PWA though. The problem, for me anyway, is I ran Lighthouse with a fresh CRA app, and this error made me think it wouldn't install a PWA. When I opened the url on Android, it did prompt to install... If Lighthouse is determining XYZ makes something not a PWA, when it is a PWA, then Lighthouse needs to be fixed to not determine that. |
going to try a fresh CRA, thanks for the feedback |
I tested this one and seems to be good. |
@patrickhulce it's the same result with just fetch. The fix was actually the one #5067 as the messages were just messed up as the service worker is not registered on you can test it here https://build-zzbfraodkg.now.sh/ |
Oooooooh, gotcha so it was always working with CRA then? |
Not entirely 😛 the bug was fixed when #4710 landed as there was a race condition when the manifest wasn't cached on time. After that one it was just a wording error in the audit. |
@frlinw we totally agree! on latest LH I don't see any of those issues on your site though so hopefully fixed in the past couple months 👍 |
@patrickhulce thanks ! I ran the audit on canary (v68) because I tought it was the latest lighthouse version but with the chrome extension it's all good. |
we're rolling the latest lighthouse to canary as we speak, look out for it next week :) |
I'm still having this issue in Chrome 67.0.3396.79. (it seems to be the same issue, as my app passes the Lighthouse audit in Chrome Canary 69.0.3455.0). Is there any workaround? |
hmmm - I get the This happens in Chrome (Version 66.0.3359.181 (Officiel version) (64-bit)) and Chrome Canary (Version 69.0.3455.0 (Officiel version) canary (64-bit)) on macOS I added the outputs of |
It depends on the Lighthouse version and not at the Chrome version. Just a short overview from myself with my website:
An interessting point is that the Lighthouse extension is tagged as version 2.10.1.3000 and the Lighthouse itself shows version 3.0.0-beta.0. @wdiechmann |
@Drag13 does using latest LH (3.0.0-beta.0) fix your issue? |
@patrickhulce I am sorry, but could you point me where I can get beta-version. On the market, I see only 2.10.1.3000 |
@Drag13 that you should be using 3.0.0-beta under the hood :) |
@Drag13 @wdiechmann @mrtnmgs You could also try the chrome extension from the chrome store. it's actually just a @fry2k said :) |
@Drag13 |
would a somewhat clearer error-message aid all of us "earthlings" to squelching your 'in-tray' ? like:
Another thing: Reflexion: |
App was here {
"short_name": "Upload",
"name": "UploadPage",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
} Could this be connected with no force redirect from http to https? |
@wdiechmann @Drag13 you can see if the manifest gets loaded correctly in the application tab |
@wardpeet great! I was of the impression that checkbox would only reload the serviceworker |
Problem was on the my side. Chrome 67.0.3396.87 - All works fine @wardpeet Thanks a lot for the help! |
@wdiechmann the magic checkbox that makes this mode work is actually "Bypass for network", between that and "Disable cache" in the network tab you should be getting fresh assets from server every time :) |
@patrickhulce yeah correct sorry! :) |
@patrickhulce @wardpeet affirmative :) thx! |
I'm closing this issue, I'm pretty sure this one got fixed. if not please create a new ticket with new information. |
This error is actually pretty hard to fix if you think you are.
At the moment I'm caching the index.html page and I've set the start_url to index.html and I still get this error.
I can even go from
DevTools > Application > Manifest > start_url
link to the page, switch to offline in network panel and reload the page and get the full page from the service worker.Any ideas how to debug this?
The text was updated successfully, but these errors were encountered: