Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

auto-chrome

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auto-chrome - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

test/page/selector.js

4

lib/Chrome.js

@@ -56,4 +56,4 @@ "use strict"

await awaitLoading.catch(info => {
logger.warn(info)
await awaitLoading.catch(() => {
logger.warn(`打开网页${url}超时`)
})

@@ -60,0 +60,0 @@

@@ -38,3 +38,3 @@ "use strict"

let { result } = await this.page.send('Runtime.callFunctionOn', {
let message = await this.page.send('Runtime.callFunctionOn', {
executionContextId: this.page.contextId,

@@ -48,9 +48,18 @@ functionDeclaration: func.toString(),

if (result.className === 'TypeError') {
logger.error(new Error(result.description))
return
if (message) {
const { className, description } = message.result
if (className === 'TypeError') {
logger.error(new Error(description))
}
return message.result
} else {
return { description: "返回值为空" }
}
return result
} else {

@@ -57,0 +66,0 @@

@@ -31,3 +31,6 @@ "use strict"

this.chrome.send("Target.sendMessageToTarget", { sessionId: this.sessionId, message })
this.chrome.send("Target.sendMessageToTarget", {
sessionId: this.sessionId,
message
})

@@ -34,0 +37,0 @@ return new Promise((resolve, reject) => {

@@ -65,4 +65,4 @@ "use strict"

await this.awaitLoading.catch(info => {
logger.warn(info)
await this.awaitLoading.catch(() => {
logger.warn(`打开网页${url}超时`)
})

@@ -77,5 +77,5 @@

*/
async goPrev() {
async prev() {
return await this.go({ relative: -1 });
return await this.history({ relative: -1 });

@@ -87,5 +87,5 @@ }

*/
async goNext() {
async next() {
return await this.go({ relative: 1 })
return await this.history({ relative: 1 })

@@ -100,3 +100,3 @@ }

*/
async go(options) {
async history(options) {

@@ -126,4 +126,2 @@ const { entries, currentIndex } = await this.send('Page.getNavigationHistory')

func = func.toString()
args = args.map(function (value) {

@@ -133,3 +131,3 @@ return { value }

let result = await this.document.evaluate({
return await this.document.evaluate({
func,

@@ -140,11 +138,2 @@ args,

if (result.className === 'TypeError') {
logger.error(new Error(result.description))
return
}
if (result.value) {
return result.value
}
}

@@ -157,8 +146,4 @@ /**

let element = await this.document.$(selector)
return await this.document.$(selector)
if (element) {
return element
}
}

@@ -171,8 +156,4 @@ /**

let element = await this.document.$$(selector)
return await this.document.$$(selector)
if (element) {
return element
}
}

@@ -281,4 +262,6 @@ /**

return await this.evaluate(document => document.title)
let { value } = await this.evaluate(document => document.title)
return value
}

@@ -290,4 +273,6 @@ /**

return await this.evaluate(() => window.location.href)
let { value } = await this.evaluate(() => window.location.href)
return value
}

@@ -294,0 +279,0 @@ }

{
"name": "auto-chrome",
"version": "0.6.2",
"version": "0.6.3",
"description": "使用Node.js操作Chrome或Chromium,高仿真的用户行为模拟器",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -56,7 +56,4 @@ # auto-chrome

## autoChrome(options)
## API
### class: autoChrome(options)
* `options` *Object* 全局实例配置选项,优先级低于page

@@ -98,31 +95,35 @@

#### chrome.keyboard
* `return` *Chrome* Chrome类实例
## class: Chrome
### chrome.keyboard
鼠标操作,page.keyboard的快捷引用
#### chrome.mouse
### chrome.mouse
鼠标操作,page.mouse的快捷引用
#### chrome.touch
### chrome.touch
触控设备操作,page.touch的快捷引用
#### chrome.pages
### chrome.pages
包含所有打开page的Map对象
#### chrome.page
### chrome.page
当前激活状态的page
#### chrome.newPage(url)
### chrome.newPage(url)
* `url` *String* 打开网页地址,缺省时打开空白网页
#### chrome.closePage(pageId)
### chrome.closePage(pageId)
* `pageId` *String* 要删除page的id
#### chrome.send(method, params)
### chrome.send(method, params)

@@ -135,3 +136,3 @@ 发送原始的chrome devtools协议消息

#### chrome.close()
### chrome.close()

@@ -141,18 +142,17 @@ 关闭浏览器

## class: Page
### class: Page
### page.mouse
#### page.mouse
鼠标实例
#### page.keyboard
### page.keyboard
键盘实例
#### page.touch
### page.touch
触控设备实例
#### page.emulate(options)
### page.emulate(options)

@@ -179,7 +179,7 @@ 设备仿真,直接调用该方法可能导致混乱,正常应该由事件驱动在创建标签执行page.emulate(),手动调用会存在延时覆盖问题。

#### page.goto(url)
### page.goto(url)
在标签内打开新网页
#### page.evaluate(pageFunction, arg, arg, ...)
### page.evaluate(pageFunction, ...arg)

@@ -190,6 +190,8 @@ 向页面注入js函数,获取执行后的返回值

* `arg` *\** 可序列化参数,不支持函数
* `arg` * 可序列化参数,不支持函数
#### page.$(selector)
* `return` *Object* 远程资源相关信息,[RemoteObject](https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-RemoteObject)
### page.$(selector)
选择单个元素

@@ -201,3 +203,3 @@

#### page.$$(selector)
### page.$$(selector)

@@ -210,3 +212,3 @@ 选择多个元素

#### page.click(selector)
### page.click(selector)

@@ -217,3 +219,3 @@ 通过CSS选择器点击元素

#### page.type(selector, text, options)
### page.type(selector, text, options)

@@ -230,3 +232,3 @@ 通过CSS选择器聚焦input,输入文本

#### page.send(method, params)
### page.send(method, params)

@@ -240,3 +242,3 @@ 发送包含session的原始chrome devtools协议消息

#### page.scroll(selector)
### page.scroll(selector)

@@ -247,3 +249,3 @@ 滚动至指定元素可视区域,会尽量沿Y轴居中

#### page.focus(selector)
### page.focus(selector)

@@ -254,3 +256,3 @@ 通过CSS选择器聚焦元素

#### page.getBoundingRect(selector)
### page.getBoundingRect(selector)

@@ -261,11 +263,11 @@ 通过CSS选择器获取元素坐标,值由getBoundingClientRect()函数获取

#### page.close()
### page.close()
关闭标签
#### page.goBack()
### page.goBack()
导航到上一个历史标签页
#### page.goForward()
### page.goForward()

@@ -281,3 +283,3 @@ 导航到下一个历史标签页

#### elment.$(selector)
### elment.$(selector)

@@ -290,3 +292,3 @@ * `selector` *String*

#### elment.$$(selector)
### elment.$$(selector)

@@ -299,3 +301,3 @@ * `selector` *String*

#### elment.get(name)
### elment.get(name)

@@ -306,3 +308,3 @@ * `name` *String*

#### elment.set(name, value)
### elment.set(name, value)

@@ -315,3 +317,3 @@ * `name` *String* 属性名称

#### elment.value(value)
### elment.value(value)

@@ -322,7 +324,7 @@ * `value` *String* 赋值

#### elment.focus()
### elment.focus()
聚焦元素
#### elment.getBoundingRect()
### elment.getBoundingRect()

@@ -334,5 +336,5 @@ 通过getBoundingClientRect函数获取元素大小、坐标信息

### class: Mouse
## class: Mouse
#### mouse.click(x, y, options)
### mouse.click(x, y, options)

@@ -348,3 +350,3 @@ 新增模拟鼠标移动轨迹,原click可能出于效率考虑,只会触发一次mousemoved

#### mouse.move(x, y, options)
### mouse.move(x, y, options)

@@ -358,3 +360,3 @@ 将steps默认值改为20,原值为1,即只触发一次。移动距离相同时,触发次数越少,对应的移动速度越快

#### mouse.scroll(x, y, step)
### mouse.scroll(x, y, step)

@@ -371,5 +373,5 @@ 滚动至指定坐标,目前仅支持纵向滚动

### class: Touch
## class: Touch
#### touch.slide({start, end, steps})
### touch.slide({start, end, steps})

@@ -395,3 +397,3 @@ 模拟touch单点滑动手势

#### touch.scroll(x, y, options)
### touch.scroll(x, y, options)

@@ -398,0 +400,0 @@ 通过touch滚动页面至指定的可视坐标

@@ -69,7 +69,7 @@ "use strict"

await await chrome.page.goPrev()
await await chrome.page.prev()
await sleep(1500)
await await chrome.page.goNext()
await await chrome.page.next()

@@ -90,11 +90,11 @@ await sleep(1500)

await await chrome.page.goPrev()
await await chrome.page.prev()
await sleep(2000)
await await chrome.page.goPrev()
await await chrome.page.prev()
await sleep(1500)
await await chrome.page.goPrev()
await await chrome.page.prev()

@@ -101,0 +101,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc