feat(frame): introduce Frame.goto and Frame.waitForNavigation (#3276)

This patch introduces API to manage frame navigations.
As a drive-by, the `response.frame()` method is added as a shortcut
for `response.request().frame()`.

Fixes #2918.
This commit is contained in:
Andrey Lushnikov
2018-09-20 11:31:19 -07:00
committed by GitHub
parent ad49f792a4
commit 5acf953104
8 changed files with 193 additions and 20 deletions

View File

@@ -37,16 +37,19 @@ const utils = module.exports = {
* @param {!Page} page
* @param {string} frameId
* @param {string} url
* @return {!Puppeteer.Frame}
*/
attachFrame: async function(page, frameId, url) {
await page.evaluate(attachFrame, frameId, url);
const handle = await page.evaluateHandle(attachFrame, frameId, url);
return await handle.asElement().contentFrame();
function attachFrame(frameId, url) {
async function attachFrame(frameId, url) {
const frame = document.createElement('iframe');
frame.src = url;
frame.id = frameId;
document.body.appendChild(frame);
return new Promise(x => frame.onload = x);
await new Promise(x => frame.onload = x);
return frame;
}
},