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

Offline mode doesn't work in Firefox #1645

Open
bgrgicak opened this issue Jul 24, 2024 · 16 comments
Open

Offline mode doesn't work in Firefox #1645

bgrgicak opened this issue Jul 24, 2024 · 16 comments
Labels
[Aspect] Networking [Type] Bug An existing feature does not function as intended

Comments

@bgrgicak
Copy link
Collaborator

Offline mode works in Chrome and Safari, but throws an error in Firefox.

TypeError: NetworkError when attempting to fetch resource.

Recreate

  • Go to Playground.WordPress.net in Firefox
  • Click File > Work Offline (in the window header menu)
  • Reload and see error
@bgrgicak bgrgicak added [Type] Bug An existing feature does not function as intended [Aspect] Networking labels Jul 24, 2024
@bgrgicak bgrgicak moved this from Inbox to Up next in Playground Board Jul 24, 2024
@brandonpayton
Copy link
Member

The failure I'm seeing is for:

https://www.googletagmanager.com/gtag/js?id=G-SOME-IDENTIFIER

Screenshot 2024-07-24 at 6 41 12 PM

@brandonpayton
Copy link
Member

The failure I'm seeing is for:

https://www.googletagmanager.com/gtag/js?id=G-SOME-IDENTIFIER

That may be a red herring. After locally removing the index.html dependency on googletagmanager.com and confirming it is no longer used by index.html in the browser, the error still occurs.

@brandonpayton
Copy link
Member

@bgrgicak, I wanted to know more about the Offline work and spent more time looking at this, setting fetch breakpoints in the service worker and in the main page dev tools, and comparing request URLs with those satisfied from the cache. AFAICT, there don't appear to be any files not found in the cache.

Those logs are here. There are 28 entries, 14 fetches and 14 corresponding cache hits. And in the dev tools Network tab, there were 14 requests logged. I didn't notice any differences between the 14 file names but did not confirm entry by entry.

I also spent time trying to find the origin of the "NetworkError when attempting to fetch resource" error but haven't had any luck. I was eager to help out and have a fix waiting as you started your day, but it didn't work out. :) I'm curious what you will find here. It will be super interesting to learn the source of this issue.

@bgrgicak
Copy link
Collaborator Author

That may be a red herring. After locally removing the index.html dependency on googletagmanager.com and confirming it is no longer used by index.html in the browser, the error still occurs.

It's ok for GTM to fail. It also fails in Chrome because we don't cache it.

@bgrgicak
Copy link
Collaborator Author

I was eager to help out and have a fix waiting as you started your day, but it didn't work out. :)

Thank you! It felt really good seeing that you helped. 🙂

@bgrgicak
Copy link
Collaborator Author

When I check the network requests while offline and compare it to online, it stops before requesting the SQLite plugin.

This plugin isn't preached, so I assume that there is something different in how FF fetches these files from cache.

I can see the file in cache.

When online the file is fetched from the server and not returned by the service worker. In Chrome it's returned by the worker.

@brandonpayton
Copy link
Member

brandonpayton commented Jul 26, 2024

Ah, good call, comparing between online and offline requests.

I poked at this a bit more at the end of the day but unfortunately don't have more to share.

@adamziel
Copy link
Collaborator

adamziel commented Jul 29, 2024

It seems like all fetch() requests in the web worker fail when offline:

CleanShot 2024-07-29 at 11 55 50@2x
CleanShot 2024-07-29 at 11 55 43@2x

I'm able to open both these files in a new tab, but somehow firefox cannot fetch them at the time the service worker requests them.

Two more issues I found in Firefox:

  • The offline mode only works after the second time you visit playground.wordpress.net
  • Firefox sometimes fails to cache specific files:

CleanShot 2024-07-29 at 11 56 57@2x

All of these seem like Firefox bugs. Perhaps we can work around them by poking around the worker lifecycle or claim() calls.

Aha, I am actually turning my wifi off. The "Work Offline" mode seems to be different from actually being offline so I am not using it.

Also, it is so weird this works on a localhost but not on playground.wordpress.net 🤔

@adamziel
Copy link
Collaborator

I wonder if these fetch() requests even make it to the service worker. It seems like that can only be debugged in Firefox nightly:

https://firefox-source-docs.mozilla.org/devtools-user/application/service_workers/index.html#debugging-service-workers

@adamziel
Copy link
Collaborator

One problem seems to be related to the service worker lifecycle. I'm testing on localhost as follows:

  1. Start the Playground server (php -S 127.0.0.1:9996 -t dist/packages/playground/wasm-wordpress-net)
  2. Open it in firefox
  3. Refresh the page
  4. Close the tab
  5. Stop the Playground server
  6. Go to 127.0.0.1:9996

This is what I see on the first page load:

CleanShot 2024-07-29 at 12 22 40@2x

If I navigate to admin and then back to the homepage, the CSS is there. This is what we've seen in Chrome before #1643. It doesn't seem to be kicking in in Firefox.

This may or may not be related to the larger issue we're seeing on playground.wordpress.net.

@adamziel
Copy link
Collaborator

adamziel commented Jul 29, 2024

Idea for a short debugging feedback loop:

  1. Create a local https:// setup
  2. Serve the build Playground through that https domain
  3. Hope it would break in the same way as playground.wordpress.net does
  4. Edit the built files directly to avoid long waiting for the build

Alternatively, we could start a staging environment and do that there.

@brandonpayton
Copy link
Member

I wonder if these fetch() requests even make it to the service worker. It seems like that can only be debugged in Firefox nightly:

https://firefox-source-docs.mozilla.org/devtools-user/application/service_workers/index.html#debugging-service-workers

@adamziel It's possible to debug Service Workers in Firefox today using dedicated dev tools opened via this page: about:debugging#/runtime/this-firefox. But debugging via web page dev tools (as supported by Firefox Nightly) looks like a huge UX improvement.

Screenshot 2024-07-29 at 8 00 03 AM

@brandonpayton brandonpayton self-assigned this Jul 30, 2024
@brandonpayton
Copy link
Member

Taking this one at @bgrgicak's request

@brandonpayton
Copy link
Member

I took another look at this tonight and was able to reproduce the issue with a website build in Firefox.

Now, it is just working:

  • Build the website
  • Run php -S 127.0.0.1:8888 -t dist/packages/playground/wasm-wordpress-net
  • Load http://127.0.0.1:8888/ in Firefox
  • Open dev tools and confirm caching is disabled via the Network tab
  • Kill the php server
  • Reload and observe that Firefox loads Playground
  • Enable "Work offline"
  • Reload and observe that Firefox loads Playground
  • Use the Application tab to browse the Cache storage. Search for the sqlite zip entry and delete it.
  • Reload and observe the Playground fails to load due to fetch error

This is with Firefox v132. It looks like Firefox might have updated this evening as I was testing. Firefox stalled, so I killed it. And after I restarted it, offline mode seemed to work just fine.

@bgrgicak would you be up for doing a quick test with Firefox v132 to see if it is working for you as well?

@bgrgicak
Copy link
Collaborator Author

bgrgicak commented Nov 4, 2024

I can confirm that Playground works offline in Firefox 132 and 133, but only locally.
I tested Playground.WordPress.net in Firefox 133 and I still get the network error.

Image

@brandonpayton
Copy link
Member

I can confirm that Playground works offline in Firefox 132 and 133, but only locally.
I tested Playground.WordPress.net in Firefox 133 and I still get the network error.

Thank you for testing this. :) So this became slightly harder to test because we apparently can't use a loopback address. Good thought to test the actual Playground site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Aspect] Networking [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants