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

Hydrogen service worker confuses multiple client instances #3

Open
jryans opened this issue Oct 12, 2021 · 0 comments
Open

Hydrogen service worker confuses multiple client instances #3

jryans opened this issue Oct 12, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@jryans
Copy link
Contributor

jryans commented Oct 12, 2021

The Hydrogen service worker causes general confusion when running multiple instances at the same time like Patience does, since all instances hear what the others are doing.

We'll need to do at least one of:

  • Isolate each client on its own domain (blocks direct window access)
  • Run a modified Hydrogen instance with service workers disabled
  • Craft some hack to make it seem like the browser doesn't support service workers

We are already attempting the hack approach:

// Inject a helper script to disable service workers, as the multiple
// frames on same domain otherwise affect each other via the service
// worker.
const helperScript = frameDoc.createElement("script");
helperScript.textContent = "(" + function() {
// We can't delete navigator.serviceWorker, so instead we hide it
// with a proxy.
const navigatorProxy = new Proxy({}, {
has: (target, key) => key !== "serviceWorker" && key in target,
});
Object.defineProperty(window, "navigator", {
value: navigatorProxy,
});
console.log("Service worker support disabled");
} + ")()";
frameDoc.head.prepend(helperScript);

...but it seems to only work in Firefox. Recent Chrome appears to run the frame's document before the hack has a chance to mess with things.

@jryans jryans added the bug Something isn't working label Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant