@@ -56,6 +56,40 @@ class GitHubPagesWasmPlugin {
5656 console.error('Error fetching sql-wasm.wasm directly:', error);
5757 });
5858
59+ // Override the SQL.js module loading mechanism
60+ console.log('Attempting to override SQL.js WASM loading...');
61+
62+ // Try to intercept the SQL.js WASM loading by overriding the module
63+ if (typeof window !== 'undefined') {
64+ // Store original methods
65+ const originalWebAssemblyCompile = WebAssembly.compile;
66+ const originalWebAssemblyCompileStreaming = WebAssembly.compileStreaming;
67+
68+ // Override WebAssembly.compile
69+ WebAssembly.compile = function(buffer) {
70+ console.log('WebAssembly.compile called');
71+ if (buffer instanceof ArrayBuffer) {
72+ const uint8Array = new Uint8Array(buffer);
73+ const firstBytes = Array.from(uint8Array.slice(0, 4));
74+ console.log('WebAssembly.compile buffer first 4 bytes:', firstBytes);
75+ if (firstBytes[0] === 0x3c && firstBytes[1] === 0x21) {
76+ console.error('❌ WebAssembly.compile received HTML instead of WASM!');
77+ throw new Error('Received HTML instead of WebAssembly binary in compile');
78+ }
79+ }
80+ return originalWebAssemblyCompile.call(this, buffer);
81+ };
82+
83+ // Override WebAssembly.compileStreaming
84+ WebAssembly.compileStreaming = function(source) {
85+ console.log('WebAssembly.compileStreaming called with:', source);
86+ return originalWebAssemblyCompileStreaming.call(this, source).catch(error => {
87+ console.error('WebAssembly.compileStreaming failed:', error);
88+ throw error;
89+ });
90+ };
91+ }
92+
5993 // Store original fetch
6094 const originalFetch = window.fetch;
6195
@@ -90,16 +124,19 @@ class GitHubPagesWasmPlugin {
90124 return originalFetch(url, options);
91125 };
92126
93- // Override XMLHttpRequest to handle .wasm files
94- const originalXHROpen = XMLHttpRequest.prototype.open;
95- const originalXHRSend = XMLHttpRequest.prototype.send;
96-
127+ // Also intercept all requests to see what SQL.js is actually requesting
128+ const originalOpen = XMLHttpRequest.prototype.open;
97129 XMLHttpRequest.prototype.open = function(method, url, ...args) {
98- console.log('XHR open called with URL:', url);
99- this._url = url;
100- return originalXHROpen.call(this, method, url, ...args);
130+ console.log('XHR open:', method, url);
131+ if (url && url.includes('sql') && url.includes('wasm')) {
132+ console.log('🔍 SQL.js WASM XHR request detected:', url);
133+ }
134+ return originalOpen.call(this, method, url, ...args);
101135 };
102136
137+ // Override XMLHttpRequest to handle .wasm files
138+ const originalXHRSend = XMLHttpRequest.prototype.send;
139+
103140 XMLHttpRequest.prototype.send = function(data) {
104141 if (this._url && this._url.endsWith('.wasm')) {
105142 console.log('Intercepting XHR WASM request:', this._url);
0 commit comments