Skip to content

Commit

Permalink
release build: v04.00.04
Browse files Browse the repository at this point in the history
fix: remove all ES6 JS code when API <= 20 (Android 4.4 KitKat)

implications:
  * JS Sandbox is disabled
      equivalent to: @Flag noJsSandbox
  * window.GM is undefined
      because: window.Promise is undefined

notes:
  * tested and confirmed to work in Android 4.4 KitKat
  * Android 5.0 and higher supports an upgradeable System WebView
  • Loading branch information
warren-bank committed Dec 5, 2023
1 parent 7fc3c12 commit 687d698
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ public class WmScriptJsCode extends ScriptJsCode {
public static void initStaticResources(Context context) {
if (TextUtils.isEmpty(WM_API_V4_POLYFILL)) {
try {
WM_API_V4_POLYFILL = ResourceHelper.getRawStringResource(context, R.raw.wm_api_v4_polyfill);
if (useES6)
WM_API_V4_POLYFILL = ResourceHelper.getRawStringResource(context, R.raw.wm_api_v4_polyfill);
}
catch(Exception e) {}
}
if (TextUtils.isEmpty(WM_CLOSURE)) {
try {
WM_CLOSURE = ResourceHelper.getRawStringResource(context, R.raw.wm_closure);
if (useES6)
WM_CLOSURE = ResourceHelper.getRawStringResource(context, R.raw.wm_closure);
}
catch(Exception e) {}
}
Expand Down
4 changes: 2 additions & 2 deletions android-studio-project/constants.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project.ext {
releaseVersionCode = Integer.parseInt("004000311", 10) //Integer.MAX_VALUE == 2147483647
releaseVersion = '004.00.03-11API'
releaseVersionCode = Integer.parseInt("004000411", 10) //Integer.MAX_VALUE == 2147483647
releaseVersion = '004.00.04-11API'
javaVersion = JavaVersion.VERSION_1_8
minSdkVersion = 11
targetSdkVersion = 33
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package at.pardus.android.webview.gm.util;

import android.content.Context;
import android.os.Build;
import android.text.TextUtils;

import java.util.UUID;
Expand All @@ -12,6 +13,7 @@
import at.pardus.android.webview.gm.util.ScriptInfo;

public class ScriptJsCode {
protected static final boolean useES6 = (Build.VERSION.SDK_INT >= 21); // use ES5 in Android <= 4.4 because WebView is outdated and cannot be updated

private static final String GLOBAL_JS_OBJECT = "unsafeWindow.wrappedJSObject";

Expand Down Expand Up @@ -39,7 +41,8 @@ public static void initStaticResources(Context context) {
}
if (TextUtils.isEmpty(GM_API_V4_POLYFILL)) {
try {
GM_API_V4_POLYFILL = ResourceHelper.getRawStringResource(context, R.raw.gm_api_v4_polyfill);
if (useES6)
GM_API_V4_POLYFILL = ResourceHelper.getRawStringResource(context, R.raw.gm_api_v4_polyfill);
}
catch(Exception e) {}
}
Expand All @@ -52,7 +55,10 @@ public static void initStaticResources(Context context) {
}
if (TextUtils.isEmpty(JS_CLOSURE_2)) {
try {
JS_CLOSURE_2 = ResourceHelper.getRawStringResource(context, R.raw.js_closure_2);
if (useES6)
JS_CLOSURE_2 = ResourceHelper.getRawStringResource(context, R.raw.js_closure_2_es6);
else
JS_CLOSURE_2 = ResourceHelper.getRawStringResource(context, R.raw.js_closure_2_es5);
}
catch(Exception e) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ var GM_fetch = function(input, init) {
);
_parsedRespHeaders.set("X-Final-URL", finalUrl);
var options = {
status,
status: status,
statusText: resp.statusText,
headers: _parsedRespHeaders,
url: finalUrl
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var window = self = globalThis = unsafeWindow;

var userscript_wrapper = function(){

0 comments on commit 687d698

Please sign in to comment.