-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
CRX: disable extensions before running lighthouse #1492
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one will be interesting, but could be a really good thing for the extension :)
return new Promise(resolve => { | ||
let remaining = installedExtensions.length; | ||
installedExtensions.forEach(info => { | ||
chrome.management.setEnabled(info.id, enable, _ => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the extension is running this after a button click, I assume this gets around the docs warning about "In most cases this function must be called in the context of a user gesture"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea. Still falls within that click.
updateBadgeUI(); | ||
throw err; | ||
}); | ||
return enableOtherChromeExtensions(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be in runLighthouseInExtension
as devtools also runs runLighthouseForConnection
(through runLighthouseInWorker
).
(updateBadgeUI
probably should be just in runLighthouseInExtension
too. It gates itself internally by returning if no chrome.runtime
, but it could quickly get confusing if we had a bunch of noop functions in the devtools path)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
// Deliver results even if enabling extensions fails. | ||
enableOtherChromeExtensions(true).catch(err => { | ||
log.warn('Chrome', `Could not disable some extensions. ${err.message}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disable
-> enable
? This seems like a big problem if it ever happens...worth bubbling up to the "Report Error" level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. For the other, I don't think it's a good UX if LH fails because an extension fails to enable. That was my intention at least. I'm not sure how enabling could fail, but users can still get results if they do.
updateBadgeUI(); | ||
|
||
enableOtherChromeExtensions(true).catch(err => { | ||
log.warn('Chrome', `Could not enable/disable some extensions. ${err.message}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feels like we should track what state we weren't able to achieve (mostly in case we can't reenable extensions)? Would probably need a separate variable from lighthouseIsRunning
to track that though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are you thinking? And how would it surface to the user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question. I don't actually know a great way, but I'm concerned there will be some corner case of permissions or something where we end up silently disabling some people's extensions and we won't know about it until someone notices (or we get error reporting integrated)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to know if/when the enabling/disabling can fail, but it may be risky to make that fatal. I really wish we had analytics :\
As part of your error refactoring, do you want to think about ways to surface top-level errors like this (e.g. non-gatherer errors) to the report so people can file bugs on them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#941 is really only about errors in the gatherer->artifact->audit->report pipeline. @patrickhulce will have to figure this out to get error reporting working, though.
We could make a master bug, though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -277,6 +311,17 @@ window.isRunning = function() { | |||
return lighthouseIsRunning; | |||
}; | |||
|
|||
// Get list of installed extensions that are enabled and can be disabled. | |||
// Extensions are not allowed to be disabled if they are under an admin policy. | |||
chrome.management.getAll(installs => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also needs to not run in devtools. Can just nest in the if statement below in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
function enableOtherChromeExtensions(enable) { | ||
return new Promise(resolve => { | ||
let remaining = installedExtensions.length; | ||
installedExtensions.forEach(info => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could also do
return Promise.all(installedExtensions.map(info => {
return new Promise(resolve => {
chrome.management.setEnabled(info.id, enable, resolve);
});
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* @param {!Promise} | ||
*/ | ||
function enableOtherChromeExtensions(enable) { | ||
return new Promise(resolve => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will you add a log.log
or log.verbose
about enabling or disabling extensions? Worth including installedExtensions.length
in the log message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
how does the permission prompt look for |
PTAL |
updateBadgeUI(); | ||
throw err; | ||
}); | ||
return Runner.run(connection, runOptions) // Run Lighthouse. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can revert this block of changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a proper 4-space indent. No code changes.
https://github.com/GoogleChrome/lighthouse/pull/1492/files?w=1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only two spaces for chaining though, just to keep everyone on their toes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I think this is one place we diverge from Google style, but it's so common in open source JS that we've pretty much unquestioningly done it throughout LH)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not consistent, but I'll revert to be consistent with the file.
If we want to enforce something other than Goog style, there really should be an eslint rule.
.then(url => window.runLighthouseForConnection(connection, url, options, requestedAggregations)) | ||
.then(results => { | ||
// Deliver results even if enabling extensions fails. | ||
enableOtherChromeExtensions(true).catch(err => { | ||
log.warn('Chrome', `Could not enable some extensions. ${err.message}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should upgrade to log.error
, but will enableOtherChromeExtensions
ever actually reject? The docs mention that it could fail but don't mention how it will fail. Presumably it won't throw but will do the callback with an error or set lastError
or something? We should hook that up to the reject
callback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I remember it throwing, but will check. If not, we can monitor lastError
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like it does throw, but the error is from not checking lastError
:) "Unchecked runtime.lastError while running management.setEnabled
"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. this is now in the promise flow.
const blobURL = window.createReportPageAsBlob(results, 'extension'); | ||
chrome.tabs.create({url: blobURL}); | ||
}).catch(err => { | ||
enableOtherChromeExtensions(true).catch(err => { | ||
log.warn('Chrome', `Could not enable/disable some extensions. ${err.message}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
PTAL |
.then(url => window.runLighthouseForConnection(connection, url, options, requestedAggregations)) | ||
.then(results => { | ||
enableOtherChromeExtensions(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these have to be returned for the rejection to get into the promise chain.
.then(results => {
return enableOtherChromeExtensions(true).then(_ => {
const blobURL = window.createReportPageAsBlob(results, 'extension');
chrome.tabs.create({url: blobURL});
});
}).catch(err => {
return enableOtherChromeExtensions(true).then(_ => {
throw err;
});
});
maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R: all
Fixes #1483.