本文整理汇总了TypeScript中chrome-remote-interface.Version函数的典型用法代码示例。如果您正苦于以下问题:TypeScript Version函数的具体用法?TypeScript Version怎么用?TypeScript Version使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Version函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('screenshot by selector', async t => {
const version = await CDP.Version()
const versionMajor = parseInt(/Chrome\/(\d+)/.exec(version['User-Agent'])[1])
// clipping will only work on chrome 61+
const chromeless = new Chromeless({ launchChrome: false })
const screenshot = await chromeless.goto(testUrl).screenshot('img')
await chromeless.end()
const png = await getPngMetaData(screenshot)
t.is(png.width, versionMajor > 60 ? 512 : 1440)
t.is(png.height, versionMajor > 60 ? 512 : 900)
})
示例2: setViewport
private async setViewport(client: Client) {
const { viewport = {} } = this.options
const config: any = {
deviceScaleFactor: 1,
mobile: false,
scale: viewport.scale || 1,
fitWindow: false, // as we cannot resize the window, `fitWindow: false` is needed in order for the viewport to be resizable
}
const { host, port } = this.options.cdp
const versionResult = await CDP.Version({ host, port })
const isHeadless = versionResult['User-Agent'].includes('Headless')
if (viewport.height && viewport.width) {
config.height = viewport.height
config.width = viewport.width
} else if (isHeadless) {
// just apply default value in headless mode to maintain original browser viewport
config.height = 900
config.width = 1440
} else {
config.height = await evaluate(
client,
(() => window.innerHeight).toString(),
)
config.width = await evaluate(
client,
(() => window.innerWidth).toString(),
)
}
await client.Emulation.setDeviceMetricsOverride(config)
await client.Emulation.setVisibleSize({
width: config.width,
height: config.height,
})
}