@ browserless/devices: 用于模拟目的的不同设备的集合.
见 设备区域 我们的网站有更多信息.
安装
使用 npm :
npm install @browserless/devices --save
关于
此软件包提供了 设备描述器库 用于浏览器模拟。 它用额外的桌面设备来扩展了Puppeteer的内置设备列表,并为设备名称解析提供了模糊的匹配能力.
这个软件包做什么
这个 @browserless/devices 软件包允许您 :
- 模拟设备 通过检索视图端口的尺寸、用户代理字符串以及设备能力
- 使用模糊匹配 来解析设备名称,即使有打字或大小写变化
- 访问扩展设备列表 包括从 Puppeteer 默认中丢失的桌面设备
设备属性
每个设备描述符包括:
| 财产 | 说明 |
|---|---|
userAgent | 浏览器用户代理字符串 |
viewport.width | 屏幕宽度, 像素 |
viewport.height | 屏幕高度( 像素) |
viewport.deviceScaleFactor | 设备像素比 (DPR) |
viewport.isMobile | 是否是移动设备 |
viewport.hasTouch | 设备是否有触摸支持 |
viewport.isLandscape | 设备是否处于地貌模式 |
自定义设备
此软件包扩展 傀儡人已知的装置 带有额外的桌面设备。 Chrome用户代理(包括Puppeteer的Android描述符)在运行时间被改写到 puppeteer.PUPPETEER_REVISIONS.chrome. Safari/iOS描述符保持不变.
下面的桌面设备不携带自己的用户代理:它们提供取景口,用户代理内部的平台符号来自主机, Macintosh; Intel Mac OS X 10_15_7 在macOS上, X11; Linux x86_64 在Linux上, Windows NT 10.0; Win64; x64 在视窗上。 工人瞄准镜总是报告真正的主机平台,所以广告主机是保持 navigator.platform 客户端的提示是一致的.
| 设备 | 决议 | 缩放 |
|---|---|---|
Macbook Pro 13 | 1280×800 (中文(简体) ) | 2个 |
Macbook Pro 15 | 1440×900 (中文(简体) ) | 2个 |
Macbook Pro 16 | 1536×960 (中文(简体) ) | 2个 |
iMac 21 | 1980×1080 (中文(简体) ) | 1个 |
iMac 21 4K | 2048×1152 (中文(简体) ) | 2个 |
iMac 24 4.5K | 4480×2520 (中文(简体) ) | 1个 |
iMac 27 | 2560×1440 (中文(简体) ) | 1个 |
iMac 27 5K | 2560×1440 (中文(简体) ) | 2个 |
模糊设备名称匹配
何时 lossyDeviceName 启用( 默认) , 包使用模糊匹配来解析设备名称 :
const createGetDevice = require('@browserless/devices')
const getDevice = createGetDevice({ lossyDeviceName: true })
// All of these resolve to "Macbook Pro 13"
getDevice({ device: 'Macbook Pro 13' })
getDevice({ device: 'macbook pro 13' })
getDevice({ device: 'MACBOOK PRO 13' })
getDevice({ device: 'macbook pro' })
getDevice({ device: 'macboo pro' }) // typo still works!
使用量
const createGetDevice = require('@browserless/devices')
const getDevice = createGetDevice()
// Get device by name
const device = getDevice({ device: 'iPhone 13' })
// => { userAgent: '...', viewport: { width: 390, height: 844, ... } }
// Override viewport properties
const customDevice = getDevice({
device: 'iPad',
viewport: { isLandscape: true }
})
// Use custom headers
const withHeaders = getDevice({
headers: { 'user-agent': 'googlebot' }
})
// Access all available devices
console.log(getDevice.deviceDescriptors)
如何适合在单体
这是一个 独立工具包 不依赖其他 @browserless/* 软件包。 其用为:
| 消费者 | 目的 |
|---|---|
@browserless/goto | 导航到 URL 时设置视图端口和用户代理 |
browserless (核心数) | 展览 getDevice() 浏览器上下文的方法 |
依赖关系
| 软件包 | 目的 |
|---|---|
didyoumean3 | 丢失设备名称分辨率的模糊字符串匹配 |
memoize-one | Caches 设备查看性能 |
require-one-of | 自动检测傀儡/傀儡核心安装 |
许可证
@ 无浏览器/设备 © 微链接,在 麻省理工学院 执照.
作者和维护者 微链接 由来自 捐助者。 。 。 .
微链接.io • GitHub 软件 微链克 • X @microlinkhq (英语)