Ultraviolet icon indicating copy to clipboard operation
Ultraviolet copied to clipboard

Ultraviolet Error With Service Worker

Open ClarrieO5 opened this issue 10 months ago • 7 comments

image

That image pops up each time I then go to inspect and go to application. And clear web data and stuff. It works. But it happens every time, on multiple proxies that run ultraviolet. E.g emerald, ruby (only occasionally)

ClarrieO5 avatar Apr 09 '24 04:04 ClarrieO5

Especially Shadow Tabbed for me at least

Evanbalam11 avatar Apr 09 '24 04:04 Evanbalam11

This is, I think, a limitation with BareMux, which Ultraviolet uses internally. Specifically the fact that it doesn't properly register the transport (the software that transports the requests) the first time you load the page. Once it does load, you should be good to go and probably won't have it happen again. doing Ctrl + Shift + R once or twice fixes it as well.

I personally have noticed this a lot and am trying to find a solid way to work around this for new users.

proudparrot2 avatar Apr 09 '24 19:04 proudparrot2

@Percslol what was the fix for this again

IncognitoTGT avatar Apr 09 '24 19:04 IncognitoTGT

This is, I think, a limitation with BareMux, which Ultraviolet uses internally. Specifically the fact that it doesn't properly register the transport (the software that transports the requests) the first time you load the page. Once it does load, you should be good to go and probably won't have it happen again. doing Ctrl + Shift + R once or twice fixes it as well.

I personally have noticed this a lot and am trying to find a solid way to work around this for new users.

Your issue is setting the transport before the service worker is ready, I already updated the ultraviolet docs to include this fix but its as easy as setting your transport when the service worker is ready like shown in the example.

navigator.serviceWorker.ready.then((sw) => {
    SetTransport("EpxMod.EpoxyClient", { wisp: "wss://wisp.mercurywork.shop/" });
    SetTransport("BareMod.BareClient", "https://example.com/bare/");
});

Percslol avatar Apr 09 '24 23:04 Percslol

I've been setting it in a .then after the register function, but I'll try this out

proudparrot2 avatar Apr 10 '24 01:04 proudparrot2

I've been setting it in a .then after the register function, but I'll try this out

Yeah turns out this is not really a fix as that promise only gets returned if the service worker is intercepting the current page.

Percslol avatar Apr 10 '24 02:04 Percslol

This is the other react related fix (which can be adapted to other frameworks like solid)

export default function AppRoutes() {
	const [init, setInit] = useState(false);
	const [config] = useConfig("proxy");
	useEffect(() => {
		if ("serviceWorker" in navigator) {
			navigator.serviceWorker
				.register("/sw.js", {
					scope: "/~/",
				})
				.then(() => {
					console.log(
						"\x1b[34;49;1m[Ephemeral] \x1B[32mINFO: Service workers registered",
					);
					BareMux.registerRemoteListener(navigator.serviceWorker.controller);
					BareMux.SetTransport(transports[config.transport], {
						wisp: config.wispServer,
					});
                                        setInit(true)
				})
				.catch((err) => {
					console.error(
						"\x1b[34;49;1m[Ephemeral] \x1B[31mERROR: Service workers registration failed",
						err,
					);
				});
		} else {
			console.error(
				"\x1b[34;49;1m[Ephemeral] \x1B[31mERROR: Service workers are not supported on this device",
			);
		}
	}, [config]);
	return init ? <RouterProvider router={routes} /> : null;
}

IncognitoTGT avatar Apr 10 '24 02:04 IncognitoTGT

this issue was resolved in 3.1.1, try updating uv-app if you are using it or updating your uv version if its your own custom frontend

closing as completed

Percslol avatar May 04 '24 18:05 Percslol