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

Fix SW scope handling of base html tag #754

Merged
merged 5 commits into from
Feb 26, 2021
Merged

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Feb 26, 2021

Description

1 Line Summary

Fixed regression introduced in #745 where we are no longer correctly handling relative URLs for the ServiceWorker scope when a <base> HTML tag is added to the page.

Details

Fixes issue where the page can't find the ServiceWorker if it is registered. Fixes the following warning + error printed to the console.

[Service Worker Status] Error Checking service worker registration / DOMException: Failed to get a ServiceWorkerRegistration: The origin of the provided documentURL ('https://www.example.com') does not match the current origin ('https://localhost:4001').
[Worker Messenger] [Page -> SW] Could not get ServiceWorkerRegistration to postMessage!

Only API affected by the base tag we were using was navigator.serviceWorker.getRegistration.

Systems Affected

  • WebSDK

Validation

Tests

Info

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
    • Tested on Edge as a new user
  • I have included test coverage for these changes or explained why they are not needed

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map
  • Avoid using global OneSignal accessor for context if possible. Instead, we can pass it to function/constructor so that we don't call OneSignal.context

Screenshots

Info

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed
    • No visual changes.

Related Tickets



This change is Reviewable

* The results in the following warning after accepting notification
permissions
* [Service Worker Status] Error Checking service worker registration / DOMException: Failed to get a ServiceWorkerRegistration: The origin of the provided documentURL ('https://www.example.com') does not match the current origin ('https://localhost:4001').
* Followed by this error:
* [Worker Messenger] [Page -> SW] Could not get ServiceWorkerRegistration to postMessage!
* A relative path passed to the browser API
navigator.serviceWorker.getRegistration respects the a base URL refined
via a base html tag.
* To combat we are making the add location.origin
* Updated getRegistration to support full URL like browsers do
* Added a rule that getRegistration should always start with
location.origin due to the HTML base tag change relative urls.
* Also updated all existing tests that did not follow this rule.
@jkasten2 jkasten2 requested review from rgomezp and itrush February 26, 2021 05:43
Copy link
Contributor

@itrush itrush left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1, 7 of 7 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @rgomezp)

@jkasten2 jkasten2 merged commit 62ed102 into master Feb 26, 2021
@jkasten2 jkasten2 deleted the fix/base_html_tag_error branch February 26, 2021 05:49
@jkasten2 jkasten2 mentioned this pull request Feb 26, 2021
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

Successfully merging this pull request may close these issues.

2 participants