Updated ContentBlockerHandler CSS_DISPLAY_NONE action type and JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_JS_SOURCE javascript implementation code

This commit is contained in:
Lorenzo Pichilli 2023-11-29 14:35:52 +01:00
parent 77bca50f0e
commit 35fea2c331
4 changed files with 24 additions and 17 deletions

View File

@ -1,3 +1,7 @@
## 1.0.3
- Updated `ContentBlockerHandler` CSS_DISPLAY_NONE action type and `JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_JS_SOURCE` javascript implementation code
## 1.0.2 ## 1.0.2
- Updated `flutter_inappwebview_platform_interface` version dependency to `1.0.2` - Updated `flutter_inappwebview_platform_interface` version dependency to `1.0.2`

View File

@ -156,7 +156,7 @@ public class ContentBlockerHandler {
final String cssSelector = action.getSelector(); final String cssSelector = action.getSelector();
final String jsScript = "(function(d) { " + final String jsScript = "(function(d) { " +
" function hide () { " + " function hide () { " +
" if (!d.getElementById('" + JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_NAME + "-css-display-none-style')) { " + " if (d.body != null && !d.getElementById('" + JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_NAME + "-css-display-none-style')) { " +
" var c = d.createElement('style'); " + " var c = d.createElement('style'); " +
" c.id = '" + JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_NAME + "-css-display-none-style'; " + " c.id = '" + JavaScriptBridgeJS.JAVASCRIPT_BRIDGE_NAME + "-css-display-none-style'; " +
" c.innerHTML = '" + cssSelector + " { display: none !important; }'; " + " c.innerHTML = '" + cssSelector + " { display: none !important; }'; " +

View File

@ -214,24 +214,27 @@ public class JavaScriptBridgeJS {
" }" + " }" +
"};"; "};";
public static final String JAVASCRIPT_BRIDGE_JS_SOURCE = "if (window.top == null || window.top === window) {" + public static final String JAVASCRIPT_BRIDGE_JS_SOURCE = "if (window." + JAVASCRIPT_BRIDGE_NAME + " != null) {" +
" if (window." + JAVASCRIPT_BRIDGE_NAME + " != null) {" + " window." + JAVASCRIPT_BRIDGE_NAME + ".callHandler = function() {" +
" window." + JAVASCRIPT_BRIDGE_NAME + ".callHandler = function() {" + " var _callHandlerID = setTimeout(function(){});" +
" var _callHandlerID = setTimeout(function(){});" + " window." + JAVASCRIPT_BRIDGE_NAME + "._callHandler(arguments[0], _callHandlerID, JSON.stringify(Array.prototype.slice.call(arguments, 1)));" +
" window." + JAVASCRIPT_BRIDGE_NAME + "._callHandler(arguments[0], _callHandlerID, JSON.stringify(Array.prototype.slice.call(arguments, 1)));" + " return new Promise(function(resolve, reject) {" +
" return new Promise(function(resolve, reject) {" + " window." + JAVASCRIPT_BRIDGE_NAME + "[_callHandlerID] = {resolve: resolve, reject: reject};" +
" window." + JAVASCRIPT_BRIDGE_NAME + "[_callHandlerID] = {resolve: resolve, reject: reject};" + " });" +
" });" + " };" +
" };" + "}"+
" }"+ "if (window.top != null && window.top !== window && window." + JAVASCRIPT_BRIDGE_NAME + " == null) {" +
"} else {" +
" window." + JAVASCRIPT_BRIDGE_NAME + " = {};" + " window." + JAVASCRIPT_BRIDGE_NAME + " = {};" +
" window." + JAVASCRIPT_BRIDGE_NAME + ".callHandler = function() {" + " window." + JAVASCRIPT_BRIDGE_NAME + ".callHandler = function() {" +
" var _callHandlerID = setTimeout(function(){});" + " var _callHandlerID = setTimeout(function(){});" +
" window.top." + JAVASCRIPT_BRIDGE_NAME + "._callHandler(arguments[0], _callHandlerID, JSON.stringify(Array.prototype.slice.call(arguments, 1)));" + " try {" +
" return new Promise(function(resolve, reject) {" + " window.top." + JAVASCRIPT_BRIDGE_NAME + "._callHandler(arguments[0], _callHandlerID, JSON.stringify(Array.prototype.slice.call(arguments, 1)));" +
" window.top." + JAVASCRIPT_BRIDGE_NAME + "[_callHandlerID] = {resolve: resolve, reject: reject};" + " return new Promise(function(resolve, reject) {" +
" });" + " window.top." + JAVASCRIPT_BRIDGE_NAME + "[_callHandlerID] = {resolve: resolve, reject: reject};" +
" });" +
" } catch (error) {" +
" return new Promise(function(resolve, reject) { reject(error); });" +
" }" +
" };" + " };" +
"}" + "}" +
"if (window." + JAVASCRIPT_BRIDGE_NAME + " != null) {" + "if (window." + JAVASCRIPT_BRIDGE_NAME + " != null) {" +

View File

@ -1,6 +1,6 @@
name: flutter_inappwebview_android name: flutter_inappwebview_android
description: Android implementation of the flutter_inappwebview plugin. description: Android implementation of the flutter_inappwebview plugin.
version: 1.0.2 version: 1.0.3
homepage: https://inappwebview.dev/ homepage: https://inappwebview.dev/
repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_android repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_android
issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues