How to store and restore cookies in a native web view?

Original Created Aug 10, 2018 | Regeneration Apr 22, 2026

I'm developing a native web view application that works well, but I'm facing an issue with cookie persistence. Every time I close and restart the app, all login/cookie information is lost.

Interestingly, HTML5 Web Storage (local db) gets restored properly, but cookies aren't preserved. Here's the basic code structure I'm using (from a Samsung example):

[Code example remains the same as in original question]

Problem Understanding

The issue occurs because cookies in the native web view aren't being persisted between app sessions, while Web Storage data is preserved. This is a common challenge when working with web views in Tizen applications.

Solution Methods

  1. Using EWebKit Cookie Management APIs:

    • Utilize the EWebKit Cookie Manager functions to properly handle cookie persistence
    • Key functions to use:
      • ewk_cookie_manager_persistent_storage_set()
      • Ewk_Cookie_Persistent_Storage
      • Ewk_Cookie_Accept_Policy
  2. JavaScript Workaround:

    • Save cookies to LocalStorage via JavaScript when the app is running
    • Read from LocalStorage and recreate cookies when the app starts
    • This approach provides a reliable alternative when native cookie persistence fails

Code Examples

For the native API solution, you would need to implement something like:

// Get the cookie manager
Ewk_Cookie_Manager* cookie_manager = ewk_context_cookie_manager_get(ewk_view_context_get(web_view));

// Set persistent storage
ewk_cookie_manager_persistent_storage_set(cookie_manager, "/path/to/cookie/file", EWK_COOKIE_PERSISTENT_STORAGE_TEXT);

For the JavaScript workaround:

// Save cookies to localStorage
document.cookie.split(';').forEach(cookie => {
    const [name, value] = cookie.split('=');
    localStorage.setItem(`cookie_${name.trim()}`, value);
});

// Restore cookies from localStorage
Object.keys(localStorage).forEach(key => {
    if (key.startsWith('cookie_')) {
        const name = key.substring(7);
        document.cookie = `${name}=${localStorage.getItem(key)}`;
    }
});

Additional Tips

  • Ensure your app has proper storage permissions in the manifest
  • Test cookie persistence thoroughly as behavior might vary across Tizen versions
  • Consider security implications when storing sensitive data in cookies

Customize your cookie preferences

You can enable or disable non-essential cookies. Essential cookies are always on to ensure the site works properly and to keep you signed in.

Necessary

These cookies are necessary for the website to function properly and cannot be switched off. They help with things like logging in and setting your privacy preferences.

Always on

Analytics

These cookies help us improve the site by tracking which pages are most popular and how visitors move around the site.

Enable analytics cookies
Public Forum Public Forum
Employees only. Please sign in with your company account.