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

CRX: disable extensions before running lighthouse #1492

Merged
merged 5 commits into from
Jan 25, 2017
Merged

Conversation

ebidel
Copy link
Contributor

@ebidel ebidel commented Jan 18, 2017

R: all

Fixes #1483.

Copy link
Member

@brendankenny brendankenny left a 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, _ => {
Copy link
Member

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"?

Copy link
Contributor Author

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)
Copy link
Member

@brendankenny brendankenny Jan 20, 2017

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)

Copy link
Contributor Author

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}`);
Copy link
Member

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?

Copy link
Contributor Author

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}`);
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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)

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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 => {
Copy link
Member

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.

Copy link
Contributor Author

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 => {
Copy link
Member

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);
  });
})

Copy link
Contributor Author

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 => {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@brendankenny
Copy link
Member

how does the permission prompt look for management?

@ebidel
Copy link
Contributor Author

ebidel commented Jan 20, 2017

The permission prompt looks like this:

screen shot 2017-01-20 at 3 21 51 pm

@ebidel
Copy link
Contributor Author

ebidel commented Jan 21, 2017

PTAL

updateBadgeUI();
throw err;
});
return Runner.run(connection, runOptions) // Run Lighthouse.
Copy link
Member

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?

Copy link
Contributor Author

@ebidel ebidel Jan 24, 2017

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

Copy link
Member

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 :)

Copy link
Member

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)

Copy link
Contributor Author

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}`);
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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"

Copy link
Contributor Author

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}`);
Copy link
Member

Choose a reason for hiding this comment

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

log.error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ebidel
Copy link
Contributor Author

ebidel commented Jan 24, 2017

I've changed is so if an extension cannot be disabled, the chain rejects and we'll know about it via the extension bug report button. We should monitor this pretty closely on the next release. If there are errors coming in, we'll want to adjust.

screen shot 2017-01-23 at 8 57 28 pm

@ebidel
Copy link
Contributor Author

ebidel commented Jan 24, 2017

PTAL

.then(url => window.runLighthouseForConnection(connection, url, options, requestedAggregations))
.then(results => {
enableOtherChromeExtensions(true);
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@ebidel
Copy link
Contributor Author

ebidel commented Jan 25, 2017

PTAL

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM

n2am8yzrz91rp5ay0

@brendankenny brendankenny merged commit 59581c7 into master Jan 25, 2017
@brendankenny brendankenny deleted the crxdisable branch January 25, 2017 00:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants