Skip to content
New issue

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

misc: puppeteer script to test a page from devtools #12145

Merged
merged 27 commits into from
Apr 13, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions lighthouse-core/scripts/pptr-run-devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,23 @@ function addSniffer(receiver, methodName, override) {
throw new Error('Cannot find method to override: ' + methodName);
}

receiver[methodName] = function() {
/**
* @param {...any} args
*/
receiver[methodName] = function(...args) {
let result;
try {
// eslint-disable-next-line prefer-rest-params
result = original.apply(this, arguments);
result = original.apply(this, args);
} finally {
receiver[methodName] = original;
}
// In case of exception the override won't be called.
try {
// eslint-disable-next-line prefer-rest-params
Array.prototype.push.call(arguments, result);
Array.prototype.push.call(args, result);
// eslint-disable-next-line prefer-rest-params
override.apply(this, arguments);
override.apply(this, args);
} catch (e) {
throw new Error('Exception in overriden method \'' + methodName + '\': ' + e);
}
Expand Down Expand Up @@ -129,12 +132,14 @@ async function readUrlList() {
/** @type {string[]} */
const urlList = [];
const rl = readline.createInterface(process.stdin, process.stdout);
rl.on('line', line => {
if (line.startsWith('#')) return;

// @ts-ignore Iterable in Node 12
adamraine marked this conversation as resolved.
Show resolved Hide resolved
for await (const line of rl) {
if (line.startsWith('#')) continue;
urlList.push(line);
});
}

return new Promise(resolve => rl.on('close', () => resolve(urlList)));
return urlList;
}

async function run() {
Expand Down