Skip to content

Commit ab10655

Browse files
committed
web: Add debugging to SQL.js wrapper to diagnose WASM loading issue
- Add console.log statements to track fetch calls and responses - Debug WebAssembly.instantiate calls - Help identify where the MIME type issue occurs
1 parent 7942bf9 commit ab10655

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

app/web/webpack.config.d/sqljs-config.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,22 @@ class GitHubPagesWasmPlugin {
3333
const sqlJsWrapperContent = `
3434
// Custom SQL.js wrapper to handle GitHub Pages MIME type issues
3535
(function() {
36+
console.log('SQL.js wrapper loaded');
37+
3638
// Store original fetch
3739
const originalFetch = window.fetch;
3840
3941
// Override fetch to handle .wasm files
4042
window.fetch = function(url, options) {
43+
console.log('Fetch called with URL:', url);
4144
if (typeof url === 'string' && url.endsWith('.wasm')) {
45+
console.log('Intercepting WASM request:', url);
4246
return originalFetch(url, options).then(response => {
47+
console.log('WASM response status:', response.status);
48+
console.log('WASM response headers:', response.headers.get('content-type'));
4349
if (response.ok) {
4450
// Clone the response and set correct headers
45-
return new Response(response.body, {
51+
const newResponse = new Response(response.body, {
4652
status: response.status,
4753
statusText: response.statusText,
4854
headers: {
@@ -51,19 +57,26 @@ class GitHubPagesWasmPlugin {
5157
'Cross-Origin-Opener-Policy': 'same-origin'
5258
}
5359
});
60+
console.log('Created new response with correct headers');
61+
return newResponse;
5462
}
5563
return response;
64+
}).catch(error => {
65+
console.error('Error fetching WASM:', error);
66+
throw error;
5667
});
5768
}
5869
return originalFetch(url, options);
5970
};
6071
61-
// Also override WebAssembly.instantiate to handle MIME type issues
72+
// Override WebAssembly.instantiate to handle MIME type issues
6273
const originalInstantiate = WebAssembly.instantiate;
6374
WebAssembly.instantiate = function(buffer, importObject) {
75+
console.log('WebAssembly.instantiate called with:', typeof buffer, buffer instanceof ArrayBuffer);
6476
// If buffer is not an ArrayBuffer, try to convert it
6577
if (!(buffer instanceof ArrayBuffer)) {
6678
if (buffer instanceof Response) {
79+
console.log('Converting Response to ArrayBuffer');
6780
return buffer.arrayBuffer().then(ab => originalInstantiate(ab, importObject));
6881
}
6982
}

0 commit comments

Comments
 (0)