Skip to content

Commit 7541727

Browse files
committed
web: Add XMLHttpRequest override to catch SQL.js WASM loading
- Override XMLHttpRequest to intercept .wasm file requests - Add debugging to detect when HTML is received instead of WASM - This should help identify how SQL.js loads its WASM file
1 parent ab10655 commit 7541727

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,43 @@ class GitHubPagesWasmPlugin {
6969
return originalFetch(url, options);
7070
};
7171
72+
// Override XMLHttpRequest to handle .wasm files
73+
const originalXHROpen = XMLHttpRequest.prototype.open;
74+
const originalXHRSend = XMLHttpRequest.prototype.send;
75+
76+
XMLHttpRequest.prototype.open = function(method, url, ...args) {
77+
console.log('XHR open called with URL:', url);
78+
this._url = url;
79+
return originalXHROpen.call(this, method, url, ...args);
80+
};
81+
82+
XMLHttpRequest.prototype.send = function(data) {
83+
if (this._url && this._url.endsWith('.wasm')) {
84+
console.log('Intercepting XHR WASM request:', this._url);
85+
const originalOnReadyStateChange = this.onreadystatechange;
86+
this.onreadystatechange = function() {
87+
if (this.readyState === 4 && this.status === 200) {
88+
console.log('XHR WASM response received, status:', this.status);
89+
// The response is already loaded, we can't modify headers at this point
90+
// But we can try to fix the response data
91+
try {
92+
const responseText = this.responseText;
93+
if (responseText && responseText.startsWith('<!')) {
94+
console.error('XHR received HTML instead of WASM for:', this._url);
95+
// This is the problem - we're getting HTML instead of WASM
96+
}
97+
} catch (e) {
98+
console.log('XHR response is binary (good)');
99+
}
100+
}
101+
if (originalOnReadyStateChange) {
102+
originalOnReadyStateChange.call(this);
103+
}
104+
};
105+
}
106+
return originalXHRSend.call(this, data);
107+
};
108+
72109
// Override WebAssembly.instantiate to handle MIME type issues
73110
const originalInstantiate = WebAssembly.instantiate;
74111
WebAssembly.instantiate = function(buffer, importObject) {

0 commit comments

Comments
 (0)