We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
有两个API请求,当拿到API1响应后的数据data,若该数据不是空数组时立刻去请求API2,否则不请求。 假设AP1为:api/tool/${id}, API2为:api/tool/${id}/tab
API
API1
data
API2
AP1
api/tool/${id}
api/tool/${id}/tab
需要拿到第一次响应后的数据,拦截第二次请求并让第二次请求等待 n 秒后再去触发API请求
const id = 100; const urlStr = `api/tool/${id}`; const Response = await newPage.waitForResponse(res => res.url().includes(urlStr)); if(!Response.ok()) { throw new Error(JSON.stringify({ErrorAPIURL: Response.url(), status: Response.status()})); } const data = JSON.parse(await Response.text());
waitForResponse 文档
const id = 100; const urlStr = `api/tool/${id}/tab`; await newPage.setRequestInterception(true); const interceptedRequest = async (request) => { if(request.url().includes(`${urlStr}/`)) { await newPage.waitForTimeout(500); request.continue(); return; } request.continue(); } if(!newPage.listenerCount('request')) { newPage.on('request', interceptedRequest); }
page.on('request')
The text was updated successfully, but these errors were encountered:
No branches or pull requests
一、场景
有两个
API
请求,当拿到API1
响应后的数据data
,若该数据不是空数组时立刻去请求API2
,否则不请求。假设
AP1
为:api/tool/${id}
,API2
为:api/tool/${id}/tab
需要拿到第一次响应后的数据,拦截第二次请求并让第二次请求等待 n 秒后再去触发API请求
二、等待第一次请求响应的数据
waitForResponse 文档
三、拦截第二次请求
page.on('request')
监听器Reference
The text was updated successfully, but these errors were encountered: