Skip to content

Commit

Permalink
core: export any page-functions as string (#5902)
Browse files Browse the repository at this point in the history
  • Loading branch information
midzer authored and paulirish committed Sep 5, 2018
1 parent adc0275 commit 552eaac
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Driver {
* @return {Promise<number>}
*/
getBenchmarkIndex() {
return this.evaluateAsync(`(${pageFunctions.ultradumbBenchmark.toString()})()`);
return this.evaluateAsync(`(${pageFunctions.ultradumbBenchmarkString})()`);
}

/**
Expand Down Expand Up @@ -302,7 +302,7 @@ class Driver {
return new __nativePromise(function (resolve) {
return __nativePromise.resolve()
.then(_ => ${expression})
.catch(${pageFunctions.wrapRuntimeEvalErrorInBrowser.toString()})
.catch(${pageFunctions.wrapRuntimeEvalErrorInBrowserString})
.then(resolve);
});
}())`,
Expand Down Expand Up @@ -513,7 +513,7 @@ class Driver {
let lastTimeout;
let cancelled = false;

const checkForQuietExpression = `(${pageFunctions.checkTimeSinceLastLongTask.toString()})()`;
const checkForQuietExpression = `(${pageFunctions.checkTimeSinceLastLongTaskString})()`;
/**
* @param {Driver} driver
* @param {() => void} resolve
Expand Down Expand Up @@ -1137,7 +1137,7 @@ class Driver {
* @return {Promise<void>}
*/
async registerPerformanceObserver() {
const scriptStr = `(${pageFunctions.registerPerformanceObserverInPage.toString()})()`;
const scriptStr = `(${pageFunctions.registerPerformanceObserverInPageString})()`;
await this.evaluateScriptOnNewDocument(scriptStr);
}

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/gather/gatherers/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Accessibility extends Gatherer {
afterPass(passContext) {
const driver = passContext.driver;
const expression = `(function () {
${pageFunctions.getOuterHTMLSnippet.toString()};
${pageFunctions.getOuterHTMLSnippetString};
${axeLibSource};
return (${runA11yChecks.toString()}());
})()`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class AnchorsWithNoRelNoopener extends Gatherer {
*/
afterPass(passContext) {
const expression = `(function() {
${pageFunctions.getOuterHTMLSnippet.toString()};
${pageFunctions.getElementsInDocument.toString()}; // define function on page
${pageFunctions.getOuterHTMLSnippetString};
${pageFunctions.getElementsInDocumentString}; // define function on page
const selector = 'a[target="_blank"]:not([rel~="noopener"]):not([rel~="noreferrer"])';
const elements = getElementsInDocument(selector);
return elements.map(node => ({
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/gather/gatherers/dobetterweb/domstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class DOMStats extends Gatherer {
*/
afterPass(passContext) {
const expression = `(function() {
${pageFunctions.getOuterHTMLSnippet.toString()};
${pageFunctions.getOuterHTMLSnippetString};
${createSelectorsLabel.toString()};
${elementPathInDOM.toString()};
return (${getDOMStats.toString()}(document.documentElement));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PasswordInputsWithPreventedPaste extends Gatherer {
*/
afterPass(passContext) {
return passContext.driver.evaluateAsync(`(() => {
${pageFunctions.getOuterHTMLSnippet.toString()};
${pageFunctions.getOuterHTMLSnippetString};
return (${findPasswordInputsWithPreventedPaste.toString()}());
})()`);
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/gather/gatherers/image-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ImageUsage extends Gatherer {
}, /** @type {Object<string, LH.Artifacts.SingleImageUsage['networkRecord']>} */ ({}));

const expression = `(function() {
${pageFunctions.getElementsInDocument.toString()}; // define function on page
${pageFunctions.getElementsInDocumentString}; // define function on page
return (${collectImageElementInfo.toString()})();
})()`;

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/gather/gatherers/seo/crawlable-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CrawlableLinks extends Gatherer {
*/
afterPass(passContext) {
const expression = `(function() {
${pageFunctions.getElementsInDocument.toString()}; // define function on page
${pageFunctions.getElementsInDocumentString}; // define function on page
const selector = 'a[href]:not([rel~="nofollow"])';
const elements = getElementsInDocument(selector);
return elements
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/gather/gatherers/seo/embedded-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EmbeddedContent extends Gatherer {
*/
afterPass(passContext) {
const expression = `(function() {
${pageFunctions.getElementsInDocument.toString()}; // define function on page
${pageFunctions.getElementsInDocumentString}; // define function on page
const selector = 'object, embed, applet';
const elements = getElementsInDocument(selector);
return elements
Expand Down
13 changes: 7 additions & 6 deletions lighthouse-core/lib/page-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ function ultradumbBenchmark() {
}

module.exports = {
wrapRuntimeEvalErrorInBrowser,
registerPerformanceObserverInPage,
checkTimeSinceLastLongTask,
getElementsInDocument,
getOuterHTMLSnippet,
ultradumbBenchmark,
wrapRuntimeEvalErrorInBrowserString: wrapRuntimeEvalErrorInBrowser.toString(),
registerPerformanceObserverInPageString: registerPerformanceObserverInPage.toString(),
checkTimeSinceLastLongTaskString: checkTimeSinceLastLongTask.toString(),
getElementsInDocumentString: getElementsInDocument.toString(),
getOuterHTMLSnippetString: getOuterHTMLSnippet.toString(),
ultradumbBenchmark: ultradumbBenchmark,
ultradumbBenchmarkString: ultradumbBenchmark.toString(),
};

0 comments on commit 552eaac

Please sign in to comment.