Note: Advice in this article will only work for JxBrowser 6. See the corresponding article for JxBrowser 7 here.(注意:本文中的建议仅适用于JxBrowser6,JxBrowser7相应文章请点击这里。)

By default, each Browser instance stores all user data such as history, cookies, cache on disk. Since 6.8 you can configure Browser instance to store all user data in memory (Chromium's "Incognito" mode), so that all user data will be cleared once your Java application is terminated.(默认情况下,每个浏览器实例在磁盘上存储所有用户数据,例如历史记录,Cookie,缓存。从6.8开始,您可以配置浏览器实例以将所有用户数据存储在内存中(Chromium的“隐身”模式),以便在终止Java应用程序后将清除所有用户数据。)

The following example demonstrates how to configure Browser instance to work in "Incognito" mode and store all user data in memory:(下面的示例演示如何配置浏览器实例以“隐身”模式工作并将所有用户数据存储在内存中:)

import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserContext;
import com.teamdev.jxbrowser.chromium.BrowserContextParams;
import com.teamdev.jxbrowser.chromium.StorageType;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

import javax.swing.*;
import java.awt.*;

 * This sample demonstrates how to configure Browser instance
 * to use in-memory data storage.
public class IncognitoModeSample {
    public static void main(String[] args) {
        // No user data will be stored to the "user-data-dir" folder.
        // This directory will be used for internal purposes
        // on macOS and Linux platforms.
        BrowserContextParams params = new BrowserContextParams("user-data-dir");

        BrowserContext browserContext = new BrowserContext(params);
        Browser browser = new Browser(browserContext);
        BrowserView view = new BrowserView(browser);

        JFrame frame = new JFrame();
        frame.add(view, BorderLayout.CENTER);
        frame.setSize(700, 500);