mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
819fa355f4
This patch: - converts all var's to let's throughout the codebase - enforces the let's over var's via the eslint rule
63 lines
1.5 KiB
JavaScript
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;
|
|
},
|
|
};
|