[backport rh-test] [bugfix] fix service worker opaqueredirect error and ensure SW controls page before mount (#6276)

Backport of #6275 to `rh-test`

Automatically created by backport workflow.

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-6276-backport-rh-test-bugfix-fix-service-worker-opaqueredirect-error-and-ensure-SW-control-2976d73d365081df8292f69e00f43e9a)
by [Unito](https://www.unito.io)

Co-authored-by: Christian Byrne <cbyrne@comfy.org>
This commit is contained in:
Comfy Org PR Bot
2025-10-25 14:56:41 +09:00
committed by GitHub
parent 570f51e60c
commit 71e851acfa
4 changed files with 24 additions and 10 deletions

View File

@@ -67,15 +67,28 @@ self.addEventListener('fetch', (event) => {
})
)
// If redirected to external storage (GCS), follow without auth headers
// The signed URL contains its own authentication in query params
if (
response.type === 'opaqueredirect' ||
response.status === 302 ||
response.status === 301
) {
// Handle redirects to external storage (e.g., GCS signed URLs)
if (response.type === 'opaqueredirect') {
// Opaqueredirect: redirect occurred but response is opaque (headers not accessible)
// Re-fetch the original /api/view URL with redirect: 'follow'
// Browser will:
// 1. Send auth headers to /api/view (same-origin)
// 2. Receive 302 redirect to GCS
// 3. Automatically strip auth headers when following cross-origin redirect
// 4. Use GCS signed URL authentication instead
return fetch(event.request.url, {
method: 'GET',
headers: headers,
redirect: 'follow'
})
}
// Non-opaque redirect (status visible) - shouldn't normally happen with redirect: 'manual'
// but handle as fallback
if (response.status === 302 || response.status === 301) {
const location = response.headers.get('location')
if (location) {
// Follow redirect manually - do NOT include auth headers for external URLs
return fetch(location, {
method: 'GET',
redirect: 'follow'

View File

@@ -86,8 +86,9 @@ app
})
// Register auth service worker after Pinia is initialized (cloud-only)
// Wait for registration to complete before mounting to ensure SW controls the page
if (isCloud) {
void import('@/platform/auth/serviceWorker')
await import('@/platform/auth/serviceWorker')
}
app.mount('#vue-app')

View File

@@ -5,5 +5,5 @@ import { isCloud } from '@/platform/distribution/types'
* Tree-shaken for desktop/localhost builds via compile-time constant.
*/
if (isCloud) {
void import('./register')
await import('./register')
}

View File

@@ -54,4 +54,4 @@ function setupCacheInvalidation(): void {
})
}
void registerAuthServiceWorker()
await registerAuthServiceWorker()