@adeprez/capacitor-user-agent

中文文档
0.1.3发布于 2024/04/15Apache-2.0TypeScriptESM + CJS零依赖近 30 天下载 3257

User Agent get/set/reset plugin for Capacitor

原始使用文档
文档目录6 节
  1. Install
  2. Usage
  3. API
  4. get()
  5. set(...)
  6. reset()

@adeprez/capacitor-user-agent

User Agent get/set/reset plugin for Capacitor

Install

npm install @adeprez/capacitor-user-agent
npx cap sync

Usage

import { UserAgent } from '@adeprez/capacitor-user-agent';

async getMyUserAgent(): Promise<string> {
  const result = await UserAgent.get();
  return result.userAgent;
}

setMyUserAgent(userAgent: string): Promise<void> {
  return UserAgent.set({userAgent});
}

API

get()

get() => Promise<{ userAgent: string; }>

Get the Webview's user agent

Returns: Promise<{ userAgent: string; }>


set(...)

set(options: { userAgent: string; reloadOnChange?: boolean; }) => Promise<void>

Update the Webview user agent (Android and iOS only). Set reloadOnChange to true to reload the page when the user agent changes (default is false). Starting from KITKAT Android version, changing the user-agent while loading a web page causes WebView to initiate loading once again.

ParamType
options{ userAgent: string; reloadOnChange?: boolean; }

reset()

reset() => Promise<void>

Reset the Webview user agent (Android and iOS only)


版本与发布记录

@adeprez/capacitor-user-agent 共发布 8 个版本,首次发布于 2022/12/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.3latest2024/04/152 年前
0.1.22024/04/102 年前
0.1.12024/03/232 年前
0.1.02024/03/232 年前
0.0.42023/09/203 年前
0.0.32022/12/093 年前

关于 @adeprez/capacitor-user-agent 的常见问题

@adeprez/capacitor-user-agent 是什么?

User Agent get/set/reset plugin for Capacitor

如何安装 @adeprez/capacitor-user-agent?

在项目目录运行 npm install @adeprez/capacitor-user-agent,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=4.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@adeprez/capacitor-user-agent 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adeprez/capacitor-user-agent 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@adeprez/capacitor-user-agent 可以商用吗?

@adeprez/capacitor-user-agent 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adeprez/capacitor-user-agent 的下载量有多少?

根据 npm 官方下载统计,@adeprez/capacitor-user-agent 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,257 次,日均约 109 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adeprez/capacitor-user-agent 还在维护吗?

最新版本 0.1.3 发布于 2024/04/15(2 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/12/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。