Profile picture of Michael GroßklausMichael Großklaus

RSS
Color scheme

TIL: Native browser spinner for asynchronous operations

function showLoading(promise) {
	navigation.addEventListener("navigate", (event) => {
		event.intercept({
			scroll: 'manual',
			handler: () => promise,
		})
	}, { once: true });
	
	return navigation.navigate(location.href).finished
}

// show browser loading UI
showLoading(new Promise((r) => setTimeout(r, 1500)));