Profile

本指南介绍如何管理 Chromium 的 Profile。

建议阅读架构指南,以更好地理解 Fuzio 架构的设计方式、工作原理及其提供的主要组件。

概述 

Profile 存储用户数据,如导航历史记录、Cookie、缓存、密码等。

Profile 类提供对以下信息的访问:Profile 的名称、存储其数据的目录的绝对路径,并提供对 Profile 相关服务的访问,例如:

  • ZoomLevels
  • Plugins
  • Proxy
  • Network
  • SpellChecker
  • CookieStore
  • HttpCache
  • HttpAuthCache
  • Downloads
  • Permissions

属于同一 ProfileBrowser 实例共享 Cookie、历史记录、缓存和其他数据。如果您不希望两个 Browser 实例共享数据,则可以创建多个 Profile 并使用属于不同 Profile 的 Browser 实例。

要创建和删除 Profile,或访问所有已创建的 Profile(包括默认 Profile),请使用 Profiles 服务:

Java
Kotlin
var profiles = engine.profiles();
val profiles = engine.profiles

默认 Profile 

创建 Engine 实例时,会自动创建默认 Profile。您可以通过以下方式访问它:

Java
Kotlin
var defaultProfile = profiles.defaultProfile();
val defaultProfile = profiles.defaultProfile()

无痕模式 

要使默认 Profile 以无痕模式运行,可以在创建 Engine 实例时使用 Incognito(无痕)选项。该选项仅影响默认 Profile。

创建 Profile 

要创建新的常规 Profile,请使用 Profiles.newProfile(String) 方法:

Java
Kotlin
var profile = profiles.newProfile("MyProfile");
val profile = profiles.newProfile("MyProfile")

Profile 将其数据(如导航历史记录、代理设置、Cookie、拼写检查器配置等)存储在用户数据目录内的一个单独目录中。

创建无痕 Profile 

要创建一个无痕 Profile,请使用以下方式:

Java
Kotlin
var profile = profiles.newIncognitoProfile("MyIncognitoProfile");
val profile = profiles.newIncognitoProfile("MyIncognitoProfile")

获取 profile 列表 

你可以使用 Profiles.list() 方法获取所有已创建的 Profile 列表(包括默认 Profile)。例如:

Java
Kotlin
var profilesList = profiles.list();
val profilesList = profiles.list()

删除 Profile 

要删除现有 Profile,请使用 Profiles.delete(Profile) 方法。例如:

Java
Kotlin
profiles.delete(profile);
profiles.delete(profile)

除 Profile 时,与其关联的所有浏览器实例将自动关闭。尝试使用已删除的 Profile 将导致 IllegalStateException 错误。

The default profile cannot be deleted. An attempt to delete the default profile leads to IllegalArgumentException.

偏好设置 

每个 Profile 都有一组偏好设置(Preferences)。你可以通过以下方法访问 Profile 的偏好设置:

Java
Kotlin
var profilePrefs = profile.preferences();
val profilePrefs = profile.preferences()

Profile 的偏好设置存储在用户数据目录中。创建 Engine 实例时,将从该目录恢复这些设置。

Web 表单自动填充 

你可以让 Fuzio 使用已保存的信息(例如用户名和密码)自动填写网页表单。当用户在网页表单中输入用户名和密码时,库可能会询问你是否希望保存这些信息。

关于如何处理保存密码请求以及如何管理所有已保存密码,请参阅密码指南。

如需禁用 Web 表单自动填充功能,请使用以下方法:

Java
Kotlin
profile.preferences().disableAutofill();
profile.preferences().disableAutofill()
微信咨询

即库客服

微信公众号二维码

技术客服

微信公众号二维码