ServiceWorker script evaluation failed due to HTTP (not HTTPS)

AI-generated summary

User verilog15 reports a ServiceWorker registration failure due to HTTP (not HTTPS), visible in dev-tools after installing plugins. Initial troubleshooting by Falco suggests checking force_https in site settings — though it’s hidden if Let’s Encrypt is enabled. verilog15 confirms not seeing the setting and seeks guidance. codinghorror suspects a botched install, while pfaffman notes that force_https is auto-enabled with Let’s Encrypt and may relate to recent regressions or email links. Falco asks if a reverse proxy is configured and guides verilog15 to check force_https via Rails console. RGJ identifies the root cause: assets were built before force_https was enabled — rebuilding should fix it. verilog15 rebuilds multiple times but still sees the error, sharing app.yml screenshots. Falco provides console commands to verify force_https, which verilog15 confirms is true. After recreating the DigitalOcean droplet and reinstalling, the error persists. Falco pushes a fix targeting WorkboxJS URLs in the service worker. pfaffman asks if this affects summary emails; Falco clarifies it doesn’t — the issue likely remains asset-related per RGJ.

I have some problem with some JS. In the dev-tools I see (after installing some official plugins):

I’m not sure where to start debugging this.
Searching for the message “Failed to register Service Worker: TypeError: Failed to register a ServiceWorker: ServiceWorker script evaluation failed” on Google suggests there is a problem with the JS but I’m don’t know where it is coming from.
Have anybody got this issue before?

Did you enable force_https in the site settings?

I’m not sure, where does it located? (tried to search in the settings via the search bar). Should it be enabled? what does it do?

Don’t have it:

My discourse is in Hebrew. I tried to search through the customized text.

Something is wrong with your install, it looks like the install is botched somehow.

Force https is enabled and hidden if let’s encrypt is enabled. There was another topic recently that had http links in summary emailsv(Configuring Activity Summary emails - #29), Could there be some regression with the code that sets the override env variable? Or something like that?

Hmm maybe. @neil your thoughts?

Hmmm didn’t know that.

So @verilog15 do you have a reverse proxy configured?

Can you enter the rails console and check the value of force_https?

I used the following guide to enable HTTPS: Set up HTTPS support with Let's Encrypt.
Maybe it’s outdated or maybe I should have used another guide? I set there the env “LETSENCRYPT_ACCOUNT_EMAIL”.
New to rails, so is it possible to explain which run in order to check the value of force_https?

This is the same issue as this one (although surfacing under different circumstances)
Having a hostname / full URL in an asset is guaranteed to cause trouble.

In this specific case, the assets were probably built before force_https was turned on.
Rebuild and you’ll be fine.

I tried to rebuild it couple of time but it still keeps that message in the devtools. Maybe something wrong with the app.yml file?




I can’t see the problem though :confused:

ssh root@your.server.ip
cd /var/discourse
./launcher enter app
rails c
puts SiteSetting.force_https

I use DigitalOcean and I destroyed the droplet and made a new one. I followed the steps (without using the guide I mentioned before, rather the script). But I still got the same error.
After running the commands I get:
image

I pushed a change to this file, can you please try an update?

Hey, @falco, Does that change affect Configuring Activity Summary emails - #32?

EDIT: I was afraid not, but both had to do with force_https, or so it seems to me.

No, my change only affects the URLs for the WorkboxJS library in our service worker file.

Since @verilog15 reports having force_https true already, I assume his problem is what @RGJ suggested.