Skip to content

Commit

Permalink
增加响应监听示例
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouyuan63 committed Nov 6, 2024
1 parent 6bce0ca commit b66e536
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/guide/instructs/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@

## browser.on(event:'request'| 'requestfaile' | 'requestfinished' | 'response',callback:Function)
监听浏览器事件
**注意:**: 监听事件是异步的且持续的,你不能期待再事件中抛出错误并中断执行。如果你需要同步使用[page.waitForResponse](https://dqa.jd.com/YinTao/guide/api/instruct.html#page.waitForResponse)
**注意:**: 监听事件是异步的且持续的,你不能期待再事件中抛出错误并中断执行。[Response 结构参考](https://playwright.dev/docs/api/class-response#response-body)

``` js
await browser.on('request',(res)=>{
// 监听页面请求
console.log('url',res._initializer.url)
})

await browser.on('response',async (res)=>{
// 监听页面请求
console.log('body:',await res.body())
})
```

## browser.route(url: string|RegExp,handler: ((route: Route, request: Request) => void), options?: {times?: number;})
Expand Down

0 comments on commit b66e536

Please sign in to comment.