Skip to content
Open
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
33 changes: 33 additions & 0 deletions app/src/main/assets/wasm-streaming-shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Fix WebAssembly streaming compilation on Android System WebView.
// On some devices WebView's compileStreaming/instantiateStreaming throws
// even when the .wasm is fetched correctly (200 application/wasm), which
// breaks sites that load a wasm video decoder for 4K playback.
// Strategy: try native streaming first (fast path on healthy engines);
// only on failure, fall back to fetch -> arrayBuffer -> compile.
(function () {
if (window.__wasmStreamingPatched) return;
if (typeof WebAssembly === 'undefined') return;
var _cs = WebAssembly.compileStreaming;
var _is = WebAssembly.instantiateStreaming;
if (typeof _cs === 'function') {
WebAssembly.compileStreaming = async function (src) {
try {
return await _cs.call(WebAssembly, src);
} catch (e) {
var resp = await src;
return WebAssembly.compile(await resp.arrayBuffer());
}
};
}
if (typeof _is === 'function') {
WebAssembly.instantiateStreaming = async function (src, imports) {
try {
return await _is.call(WebAssembly, src, imports);
} catch (e) {
var resp = await src;
return WebAssembly.instantiate(await resp.arrayBuffer(), imports);
}
};
}
window.__wasmStreamingPatched = true;
})();
3 changes: 3 additions & 0 deletions app/src/main/java/com/app/pakeplus/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,9 @@ class MainActivity : AppCompatActivity() {
val openDebug = """var vConsole = new window.VConsole()"""
view?.evaluateJavascript(vConsole + openDebug, null)
}
// inject WebAssembly streaming shim before any page script and before custom.js
val wasmShim = assets.open("wasm-streaming-shim.js").bufferedReader().use { it.readText() }
view?.evaluateJavascript(wasmShim, null)
// inject js
val injectJs = assets.open("custom.js").bufferedReader().use { it.readText() }
view?.evaluateJavascript(injectJs, null)
Expand Down