Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions v3/UNRELEASED_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ After processing, the content will be moved to the main changelog and this file

## Fixed
<!-- Bug fixes -->
- Fix `Unexpected token '<'` error when `/wails/custom.js` is missing in desktop dev mode. Added explicit 404 handler for `/wails/custom.js` and case-insensitive `Content-Type` validation in `loadOptionalScript` to prevent HTML SPA fallbacks from being injected as JavaScript. ([#5068](https://github.com/wailsapp/wails/issues/5068))

## Deprecated
<!-- Soon-to-be removed features -->
Expand Down
11 changes: 7 additions & 4 deletions v3/internal/assetserver/bundledassets/runtime.debug.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion v3/internal/assetserver/bundledassets/runtime.js

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions v3/internal/runtime/desktop/@wailsio/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ export function loadOptionalScript(url: string): Promise<void> {
return fetch(url, { method: 'HEAD' })
.then(response => {
if (response.ok) {
const script = document.createElement('script');
script.src = url;
document.head.appendChild(script);
// Verify the response is actually JavaScript and not an HTML fallback
// (e.g. Vite dev server returns index.html for unknown routes)
const contentType = (response.headers.get('content-type') || '').toLowerCase();
if (contentType.includes('javascript')) {
const script = document.createElement('script');
script.src = url;
document.head.appendChild(script);
}
Comment thread
leaanthony marked this conversation as resolved.
}
})
.catch(() => {}); // Silently ignore - script is optional
Expand Down
4 changes: 4 additions & 0 deletions v3/pkg/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func New(appOptions Options) *App {
if err != nil {
result.fatal("unable to serve transport.js: %w", err)
}
case "/wails/custom.js":
// custom.js is only served in server mode.
// Return 404 so the runtime's loadOptionalScript skips it.
http.NotFound(rw, req)
default:
next.ServeHTTP(rw, req)
}
Expand Down
Loading