Skip to content
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 fails in IIS, but works perfectly in IIS Express #10

Open
smalleythedave opened this issue Dec 15, 2019 · 10 comments
Open

Comments

@smalleythedave
Copy link

Hi,

I'm sure there must be a trivial explanation for this, but I can't find it.

I create a Blazor Web Assembly project from the template. Everything works as expected. I add the nuget, and again it all works fine and when I launch the application in IIS Express, I get the install banner in desktop Chrome, and I can install the application and run it from the desktop icon, etc. No problems at all.

Then I deploy the application to full IIS. The Blazor app downloads and runs as expected. However, the install banner doesn't appear. Looking in the Chrome dev-tools, in the console I get a message that the Service Worker was registered successfully and is controlling http://localhost. However, when I check the application tab, it lists the SW status as redundant. Reloading the page or deleting the SW always results in the same message, saying "uncaught exception in Promise, request failed".

I have searched the web and tried numerous things like custom HTTP headers, opening up permissions on inetpub to Full Control for Everyone, changing the user IIS is running under, using a valid SSL certificate (which shouldn't be necessary for localhost), etc. Always the same thing: the Blazor app downloads and runs correctly, the registration of the SW succeeds, but the status is redundant and stopped.

I have also fiddled with Chrome flags, but that would seem to be useless, since the only difference is running against IIS or Express.

Any idea what I am doing wrong?

Dave

@SQL-MisterMagoo
Copy link
Owner

I believe you have to serve the application over Https for full functionality of PWA.

@smalleythedave
Copy link
Author

smalleythedave commented Dec 15, 2019 via email

@SQL-MisterMagoo
Copy link
Owner

I don't know what could be causing this - do you see any differences in the network traffic between IIS and Express?

@smalleythedave
Copy link
Author

smalleythedave commented Dec 20, 2019 via email

@SQL-MisterMagoo
Copy link
Owner

I have reproduced the problem.

For me, something was going wrong with the list of required files and some of them were erroring on fetch, which breaks the service worker - just removing the failed files manually from the list allowed the service worker to complete and WPA functionality was restored.

I just need to figure out why they are going wrong and how to prevent the service worker from giving up or at least to provide some mechanism where you know why it has given up.

@smalleythedave
Copy link
Author

smalleythedave commented Dec 21, 2019 via email

@smalleythedave
Copy link
Author

smalleythedave commented Dec 21, 2019 via email

@GregTrevellick
Copy link

In my case the manifest.json served up successfully locally using IIS Express (via F5 in VS) with response header content type application/json.

But after deploying to server full IIS served up manifest.json with response header content type text/html (the default I believe). This caused (or was the effect of) a 401 not authorized error when serving up the manifest.json file.

I tried adding a MIME type to IIS for json files to no avail, and tried adding this to startup.cs

            var provider = new FileExtensionContentTypeProvider();
            provider.Mappings[".json"] = "application/json";
            app.UseStaticFiles(new StaticFileOptions
            {
                ContentTypeProvider = provider
            });

but neither worked.

The thing that did work, after much bingling, was to add crossorigin="use-credentials" to the html file (_Host.cshtml) like this:
<link href="/manifest.json" rel="manifest" crossorigin="use-credentials" />

@fnils
Copy link

fnils commented Mar 20, 2020

I had the same problem in my case it was the start_url in the manifest.json file. It need the full path to the website.

I found the issue generating a report using lighthouse for progressive apps in the audit window in Chrome.
F12 --> Audits.

Maybe everyone knows this already but just in case someone doesn't.

@chucker
Copy link
Contributor

chucker commented Mar 20, 2020

@fnils if your base URL isn't /, check this comment: #5 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants