Try to extract cookies just before closing recaptcha activity
Even if the page didn't auto-close
This commit is contained in:
parent
0cc890a1d1
commit
9b09028440
1 changed files with 13 additions and 9 deletions
|
@ -47,6 +47,7 @@ public class ReCaptchaActivity extends AppCompatActivity {
|
||||||
public static final String TAG = ReCaptchaActivity.class.toString();
|
public static final String TAG = ReCaptchaActivity.class.toString();
|
||||||
public static final String YT_URL = "https://www.youtube.com";
|
public static final String YT_URL = "https://www.youtube.com";
|
||||||
|
|
||||||
|
private WebView webView;
|
||||||
private String foundCookies = "";
|
private String foundCookies = "";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,23 +67,23 @@ public class ReCaptchaActivity extends AppCompatActivity {
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
|
|
||||||
|
|
||||||
WebView myWebView = findViewById(R.id.reCaptchaWebView);
|
webView = findViewById(R.id.reCaptchaWebView);
|
||||||
|
|
||||||
// Enable Javascript
|
// Enable Javascript
|
||||||
WebSettings webSettings = myWebView.getSettings();
|
WebSettings webSettings = webView.getSettings();
|
||||||
webSettings.setJavaScriptEnabled(true);
|
webSettings.setJavaScriptEnabled(true);
|
||||||
|
|
||||||
myWebView.setWebViewClient(new WebViewClient() {
|
webView.setWebViewClient(new WebViewClient() {
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
super.onPageFinished(view, url);
|
super.onPageFinished(view, url);
|
||||||
handleCookies(CookieManager.getInstance().getCookie(url));
|
handleCookies(url);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Cleaning cache, history and cookies from webView
|
// Cleaning cache, history and cookies from webView
|
||||||
myWebView.clearCache(true);
|
webView.clearCache(true);
|
||||||
myWebView.clearHistory();
|
webView.clearHistory();
|
||||||
android.webkit.CookieManager cookieManager = CookieManager.getInstance();
|
android.webkit.CookieManager cookieManager = CookieManager.getInstance();
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
cookieManager.removeAllCookies(aBoolean -> {});
|
cookieManager.removeAllCookies(aBoolean -> {});
|
||||||
|
@ -90,7 +91,7 @@ public class ReCaptchaActivity extends AppCompatActivity {
|
||||||
cookieManager.removeAllCookie();
|
cookieManager.removeAllCookie();
|
||||||
}
|
}
|
||||||
|
|
||||||
myWebView.loadUrl(url);
|
webView.loadUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -125,6 +126,7 @@ public class ReCaptchaActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveCookiesAndFinish() {
|
private void saveCookiesAndFinish() {
|
||||||
|
handleCookies(webView.getUrl()); // try to get cookies of unclosed page
|
||||||
if (!foundCookies.isEmpty()) {
|
if (!foundCookies.isEmpty()) {
|
||||||
// Give cookies to Downloader class
|
// Give cookies to Downloader class
|
||||||
DownloaderImpl.getInstance().setCookies(foundCookies);
|
DownloaderImpl.getInstance().setCookies(foundCookies);
|
||||||
|
@ -138,8 +140,10 @@ public class ReCaptchaActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void handleCookies(@Nullable String cookies) {
|
private void handleCookies(String url) {
|
||||||
if (MainActivity.DEBUG) Log.d(TAG, "handleCookies: cookies=" + (cookies == null ? "null" : cookies));
|
String cookies = CookieManager.getInstance().getCookie(url);
|
||||||
|
if (MainActivity.DEBUG) Log.d(TAG, "handleCookies: url=" + url + "; cookies=" + (cookies == null ? "null" : cookies));
|
||||||
|
Log.e(TAG, "handleCookies: url=" + url + "; cookies=" + (cookies == null ? "null" : cookies));
|
||||||
if (cookies == null) return;
|
if (cookies == null) return;
|
||||||
|
|
||||||
addYoutubeCookies(cookies);
|
addYoutubeCookies(cookies);
|
||||||
|
|
Loading…
Reference in a new issue