Skip to content

Commit

Permalink
fix: issue where cookies were not being saved when Android WebView ap…
Browse files Browse the repository at this point in the history
…p was forcibly terminated (react-native-webview#3176)
  • Loading branch information
kj-ahn-n authored Aug 20, 2024
1 parent be36de4 commit 28af371
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import com.reactnativecommunity.webview.events.TopLoadingStartEvent;
import com.reactnativecommunity.webview.events.TopRenderProcessGoneEvent;
import com.reactnativecommunity.webview.events.TopShouldStartLoadWithRequestEvent;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;

import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -54,6 +56,14 @@ public void setBasicAuthCredential(@Nullable RNCBasicAuthCredential credential)
@Override
public void onPageFinished(WebView webView, String url) {
super.onPageFinished(webView, url);
String cookies = CookieManager.getInstance().getCookie(url);
if (cookies != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().flush();
}else {
CookieSyncManager.getInstance().sync();
}
}

if (!mLastLoadFailed) {
RNCWebView reactWebView = (RNCWebView) webView;
Expand Down

0 comments on commit 28af371

Please sign in to comment.