Skip to content

fix: make sure service worker scheme is registered with allowServiceWorkers#28326

Merged
jkleinsc merged 5 commits intomasterfrom
fix-scheme-registration
Mar 23, 2021
Merged

fix: make sure service worker scheme is registered with allowServiceWorkers#28326
jkleinsc merged 5 commits intomasterfrom
fix-scheme-registration

Conversation

@zcbenz
Copy link
Contributor

@zcbenz zcbenz commented Mar 22, 2021

Description of Change

Fix #20248.

The bug was caused by 2 reasons:

  1. ServiceWorker loader does not have WebContents associated, so it did not get custom protocols registered.
  2. registerSchemesAsPrivileged is called after service worker schemes get registered, so the custom scheme could not be recognized as service worker scheme.

Checklist

Release Notes

Notes: Fix service worker not working with custom protocol.

@zcbenz zcbenz added semver/patch backwards-compatible bug fixes target/10-x-y labels Mar 22, 2021
@zcbenz zcbenz requested a review from deepak1556 March 22, 2021 11:37
@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Mar 22, 2021
@zcbenz zcbenz changed the title fix: make service worker work with custom protocol fix: make sure service worker scheme is registered with allowServiceWorkers Mar 22, 2021
@deepak1556
Copy link
Member

deepak1556 commented Mar 22, 2021

@zcbenz Nice find narrowing down the issue, an alternative approach below.

https://github.com/electron/electron/blob/master/patches/chromium/delay_lock_the_protocol_scheme_registry.patch should let us register schemes on the browser process from registerSchemesAsPrivileged . But didn't realize there was no url_util call for registering service worker schemes and savable schemes so effectively we were only registering it on network and renderer process https://source.chromium.org/chromium/chromium/src/+/master:content/common/url_schemes.cc;l=112-118.

So we can add a method url::AddServiceWorkerScheme that would allow us to register the scheme from browser process via the registerSchemesAsPrivileged method and we can keep the condition in AddAdditionalSchemes to only handle network process, this way we don't have to use the testing api.

@zcbenz
Copy link
Contributor Author

zcbenz commented Mar 23, 2021

@deepak1556 Thanks for the insights on this issue, I have changed the code to add service worker scheme directly instead of full re-registration.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Mar 23, 2021
Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

👍

@jkleinsc jkleinsc merged commit 1e9e2f8 into master Mar 23, 2021
@release-clerk
Copy link

release-clerk bot commented Mar 23, 2021

Release Notes Persisted

Fix service worker not working with custom protocol.

@jkleinsc jkleinsc deleted the fix-scheme-registration branch March 23, 2021 15:16
@trop
Copy link
Contributor

trop bot commented Mar 23, 2021

I was unable to backport this PR to "10-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor

trop bot commented Mar 23, 2021

I have automatically backported this PR to "11-x-y", please check out #28353

@trop trop bot removed the target/11-x-y label Mar 23, 2021
@trop
Copy link
Contributor

trop bot commented Mar 23, 2021

I have automatically backported this PR to "13-x-y", please check out #28354

@trop
Copy link
Contributor

trop bot commented Mar 23, 2021

I have automatically backported this PR to "12-x-y", please check out #28355

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot use service worker in html document served from custom protocol: The document is in an invalid state.

4 participants