Skip to content

Fix beforeLoad not being called in some requests #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
15 changes: 3 additions & 12 deletions src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,6 @@ else if (action.equals("loadAfterBeforeload")) {
@SuppressLint("NewApi")
@Override
public void run() {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) {
currentClient.waitForBeforeload = false;
inAppWebView.setWebViewClient(currentClient);
} else {
((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false;
}
inAppWebView.loadUrl(url);
}
});
Expand Down Expand Up @@ -718,6 +712,8 @@ public String showWebPage(final String url, HashMap<String, String> features) {
}
if (features.get(BEFORELOAD) != null) {
beforeload = features.get(BEFORELOAD);
} else {
beforeload = "";
}
String fullscreenSet = features.get(FULLSCREEN);
if (fullscreenSet != null) {
Expand Down Expand Up @@ -1169,7 +1165,6 @@ public class InAppBrowserClient extends WebViewClient {
EditText edittext;
CordovaWebView webView;
String beforeload;
boolean waitForBeforeload;

/**
* Constructor.
Expand All @@ -1181,7 +1176,6 @@ public InAppBrowserClient(CordovaWebView webView, EditText mEditText, String bef
this.webView = webView;
this.edittext = mEditText;
this.beforeload = beforeload;
this.waitForBeforeload = beforeload != null;
}

/**
Expand Down Expand Up @@ -1242,7 +1236,7 @@ public boolean shouldOverrideUrlLoading(String url, String method) {
}

// On first URL change, initiate JS callback. Only after the beforeload event, continue.
if (useBeforeload && this.waitForBeforeload) {
if (useBeforeload) {
if(sendBeforeLoad(url, method)) {
return true;
}
Expand Down Expand Up @@ -1337,9 +1331,6 @@ else if (!url.startsWith("http:") && !url.startsWith("https:") && url.matches("^
}
}

if (useBeforeload) {
this.waitForBeforeload = true;
}
return override;
}

Expand Down
2 changes: 1 addition & 1 deletion www/inappbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
_eventHandler: function (event) {
if (event && (event.type in this.channels)) {
if (event.type === 'beforeload') {
this.channels[event.type].fire(event, this._loadAfterBeforeload);
this.channels[event.type].fire(event, this._loadAfterBeforeload.bind(this));
} else {
this.channels[event.type].fire(event);
}
Expand Down