Skip to content

Disable serviceworkers on Safari browsers - #12907

Merged
joshpuetz merged 2 commits into
masterfrom
joshpuetz/disable-serviceworker-safari
Mar 4, 2021
Merged

joshpuetz merged 2 commits into
masterfrom
joshpuetz/disable-serviceworker-safari

Conversation

@joshpuetz

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

This PR turns off serviceworkers on Safari browsers (both desktop and iOS). PR #12834 refactored serviceworkers significantly, removing almost all functionality from them except for the offline page support.

Something was lost in translation because that PR has resulted in GitHub, Twitter, and possibly other authentication methods no longer working. In particular the fetch eventListener in app/views/service_worker/index.js.erb is causing issues in Safari. Bypassing this check in app/views/service_worker/index.js.erb is problematic: both navigator.userAgent as well as navigator.vendor should be checked, but Safari doesn't populate navigator.vendor in service workers.

Instead, I'm doing a check in app/assets/javascripts/serviceworker-companion.js for Safari and skipping registration of the service worker if it's true (thanks for the idea @benhalpern). As a result of this PR, the offline page for Forem will no longer load in Safari.

Related Tickets & Documents

#12834

possibly: #12899

QA Instructions, Screenshots, Recordings

To test locally, be sure to set export SKIP_SERVICEWORKERS="false" in your .env file.

On Safari, you can verify serviceworkers aren't running by navigating to http://localhost:3000, and checking the menu Developer -> Service Workers. You should not see localhost there. You should be able to login via Github as normal. There shouldn't be an offline page:

CleanShot 2021-03-04 at 14 41 15@2x

On Chrome, navigate to http://localhost:3000 and open Dev Tools. On the applications tab you should see a service worker for localhost. You should be able to login via Github as normal. The offline page should work as normal:

CleanShot 2021-03-04 at 14 40 44@2x

Added tests?

  • Yes
  • No, and this is why: no existing tests, and I'm not sure how we'd test for this. Suggestions welcomed!
  • I need help with writing tests

[Forem core team only] How will this change be communicated?

Will this PR introduce a change that impacts Forem members or creators, the
development process, or any of our internal teams? If so, please note how you
will share this change with the people who need to know about it.

  • I've updated the Developer Docs and/or
    Admin Guide, or
    Storybook (for Crayons components)
  • I've updated the README or added inline documentation
  • I will share this change in a Changelog
    or in a forem.dev post
  • I will share this change internally with the appropriate teams
  • I'm not sure how best to communicate this change and need help
  • This change does not need to be communicated, and this is why not: does not impact forem creators

[optional] What gif best describes this PR or how it makes you feel?

alt_text

@joshpuetz
joshpuetz requested review from a team, ludwiczakpawel and msarit and removed request for a team March 4, 2021 20:41
@pr-triage pr-triage Bot added the PR: unreviewed bot applied label for PR's with no review label Mar 4, 2021
@joshpuetz
joshpuetz requested review from Zhao-Andy, benhalpern, jgaskins, maestromac and rhymes and removed request for ludwiczakpawel and msarit March 4, 2021 20:42

@jgaskins jgaskins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know if not trying to load a SW at all will stop this or will it continue to use the existing installed SW?

Co-authored-by: Jamie Gaskins <jgaskins@hey.com>
@joshpuetz
joshpuetz requested review from jgaskins and mstruve March 4, 2021 20:54

@mstruve mstruve left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@pr-triage pr-triage Bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Mar 4, 2021
@joshpuetz

Copy link
Copy Markdown
Contributor Author

Do we know if not trying to load a SW at all will stop this or will it continue to use the existing installed SW?

I'm not sure TBH, will defer to ServiceWorker experts like @benhalpern

@jgaskins jgaskins left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always give it a shot. If it doesn't deregister the SW in Safari by not requesting it, maybe we can try again and run an empty SW in Safari.

@joshpuetz
joshpuetz merged commit e83101e into master Mar 4, 2021
@joshpuetz
joshpuetz deleted the joshpuetz/disable-serviceworker-safari branch March 4, 2021 21:12
@pr-triage pr-triage Bot added PR: merged bot applied label for PR's that are merged and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Mar 4, 2021
@joshpuetz joshpuetz mentioned this pull request Mar 4, 2021
1 of 5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: merged bot applied label for PR's that are merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants