puppeteer/test/frame-utils.js
Andrey Lushnikov 819fa355f4 Convert var's to let's
This patch:
- converts all var's to let's throughout the codebase
- enforces the let's over var's via the eslint rule
2017-06-22 14:58:39 -07:00

63 lines
1.5 KiB
JavaScript

const utils = module.exports = {
/**
* @param {!Page} page
* @param {string} frameId
* @param {string} url
* @return {!Promise}
*/
attachFrame: async function(page, frameId, url) {
await page.evaluate(attachFrame, frameId, url);
function attachFrame(frameId, url) {
let frame = document.createElement('iframe');
frame.src = url;
frame.id = frameId;
document.body.appendChild(frame);
return new Promise(x => frame.onload = x);
}
},
/**
* @param {!Page} page
* @param {string} frameId
* @return {!Promise}
*/
detachFrame: async function(page, frameId) {
await page.evaluate(detachFrame, frameId);
function detachFrame(frameId) {
let frame = document.getElementById(frameId);
frame.remove();
}
},
/**
* @param {!Page} page
* @param {string} frameId
* @param {string} url
* @return {!Promise}
*/
navigateFrame: async function(page, frameId, url) {
await page.evaluate(navigateFrame, frameId, url);
function navigateFrame(frameId, url) {
let frame = document.getElementById(frameId);
frame.src = url;
return new Promise(x => frame.onload = x);
}
},
/**
* @param {!Frame} frame
* @param {string=} indentation
* @return {string}
*/
dumpFrames: function(frame, indentation) {
indentation = indentation || '';
let result = indentation + frame.url();
for (let child of frame.childFrames())
result += '\n' + utils.dumpFrames(child, ' ' + indentation);
return result;
},
};