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

handleJavascriptDialogs (#1939) #2106

Merged
merged 5 commits into from
May 1, 2017
Merged

Conversation

cedricbellet
Copy link
Contributor

fixes #1939

Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

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

Woot!

Mind also adding a test to https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/test/gather/driver-test.js? There are some examples in there that stub events.

@@ -833,6 +833,16 @@ class Driver {
const promiseArr = urlPatterns.map(url => this.sendCommand('Network.addBlockedURL', {url}));
return Promise.all(promiseArr);
}

handleJavaScriptDialogs() {
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need to put the enable in the promise chain:

handleJavaScriptDialogs() {
  this.sendCommand('Page.enable').then(_ => {
    this.on('Page.javascriptDialogOpening', _ => {
      this.sendCommand('Page.handleJavaScriptDialog', {
        accept: true,
        promptText: 'Lighthouse prompt response',
      });
    });
  });
}

Can you also add a doc string to this method?

Copy link
Contributor

Choose a reason for hiding this comment

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

My first reaction was that maybe we should use this.once instead of this.on. IOW, dismiss the first prompt we see and ignore the rest. Thinking towards the future when we have auditing after the page load (SPAs), this will dismiss all prompts the page throws up. That might not be something we want to do.

That said, it's a ways out and this on is probably safer for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good, will make the changes.

@@ -833,6 +833,16 @@ class Driver {
const promiseArr = urlPatterns.map(url => this.sendCommand('Network.addBlockedURL', {url}));
return Promise.all(promiseArr);
}

handleJavaScriptDialogs() {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybedismissJavaScriptDialogs

@cedricbellet
Copy link
Contributor Author

I still need to add content to driver-test.js and am not sure why Travis is unhappy about the method. Am I missing something?

@brendankenny
Copy link
Member

am not sure why Travis is unhappy about the method.

yeah, that's a little hard to figure out because the stack trace is so truncated.

You'll need to add a mocked version of dismissJavaScriptDialogs to fake-driver.js so that unit tests can call into GatherRunner without having a real browser to talk to. Looks like a return Promise.resolve(); like most of the others in there will be sufficient since the method has nothing to do since it only makes changes via the debugger protocol.

@paulirish
Copy link
Member

@googlebot shh bby.

I added the method to the mock driver just to see if that resolves tests completely.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

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 with last question

dismissJavaScriptDialogs() {
return this.sendCommand('Page.enable').then(_ => {
this.once('Page.javascriptDialogOpening', _ => {
this.sendCommand('Page.handleJavaScriptDialog', {
Copy link
Member

Choose a reason for hiding this comment

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

if this rejects, this is intentionally unhandled (since we need to resolve as soon as 'Page.enable' is sent). Should we add a note that that's it's intended for future code readers?

@paulirish paulirish merged commit 283af87 into GoogleChrome:master May 1, 2017
@paulirish
Copy link
Member

@cedricbellet thanks!

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.

Catch and dimiss javascript dialogs/alerts/prompts
5 participants