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

core: export any page-functions as string #5902

Merged
merged 4 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions lighthouse-core/gather/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Driver {
* @return {Promise<number>}
*/
getBenchmarkIndex() {
return this.evaluateAsync(`(${pageFunctions.ultradumbBenchmark.toString()})()`);
return this.evaluateAsync(`(${pageFunctions.ultradumbBenchmarkString})()`);
}

/**
Expand Down Expand Up @@ -234,7 +234,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 @@ -445,7 +445,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 @@ -1086,7 +1086,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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is still toString()d within driver. can we update this one as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had him change it back because we use the raw function in the scripts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not both?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.gif

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this break

const result = ultradumbBenchmark();
?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah. It's still exposed the same way. It's just ALSO being exposed as a string.

patrick didnt like my idea of only exposing as string and evaling in the script/benchmark.js. :) haha

ultradumbBenchmarkString: ultradumbBenchmark.toString(),
};