1

I have an Android WebView code in which I set the cookie value. However, same operation does not work in Mozilla GeckoView.

Working sample with WebView:

public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    webView = view.findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);

    final CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(getContext());
    final CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);

    cookieManager.setCookie(url, "sessionid=123; path=/");
    cookieSyncManager.sync();

    webView.loadUrl("https://example.com");
}

Sample with GeckoView:

public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    webView = view.findViewById(R.id.webView); // GeckoView
    GeckoSession geckoSession = new GeckoSession();
    geckoSession.getSettings().setAllowJavascript(true);

    GeckoRuntimeSettings.Builder builder = new GeckoRuntimeSettings.Builder()
            .javaScriptEnabled(true);

    GeckoRuntime geckoRuntime = GeckoRuntime.create(Objects.requireNonNull(getContext()), builder.build());
    webView.setSession(geckoSession, geckoRuntime);

    final CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(getContext());
    final CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);

    cookieManager.setCookie(url, "sessionid=123; path=/");
    cookieSyncManager.sync();

    geckoSession.loadUri("https://example.com");
}

I do not get any errors, but the cookie value does not affect the loaded page.

Trugath
  • 188
  • 1
  • 7
Solinnen
  • 330
  • 1
  • 12

1 Answers1

0

GeckoView does not support setting/getting cookies as of now (Oct 2019). You can follow / vote on this bug for the implementation of it: https://bugzilla.mozilla.org/show_bug.cgi?id=1035417

Agi Sferro
  • 626
  • 3
  • 12