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

Possible improvement to core#capture #98

Closed
nathanshelly opened this issue Dec 4, 2020 · 6 comments · Fixed by #99
Closed

Possible improvement to core#capture #98

nathanshelly opened this issue Dec 4, 2020 · 6 comments · Fixed by #99
Labels
🐛 bug Something isn't working

Comments

@nathanshelly
Copy link

Hi again!

I'm trying to use the Percy CLI to test snapshots with two extra requirements that the current capture API doesn't seem to account for. One of those cases is pages behind logins and the other is an in-house implementation of frontend deploy previews for PRs.

The login case requires programmatically navigating to our company's login page and entering credentials before being redirected back to the page on which I actually want to take the screenshot. The deploy preview case requires navigating to a programmatically generated URL that sets a cookie on the client which then enables viewing the specific frontend assets associated with the corresponding PR.

At one point I was hoping to use the execute argument but if that execute function navigates to a separate page I get the following error:

[percy] Encountered an error for page: ...
[percy] Error: Evaluation failed: ReferenceError: PercyDOM is not defined
    at __puppeteer_evaluation_script__:5:20

Looking at the code this makes sense since the SDK injects @percy/dom before the execute function runs so navigating away from the page loses that injection.

Do you have a suggestion for handling this use case? If there is no straightforward answer would you all be open to a PR introducing a new argument something like executeBeforePercySetup to run any login/other setup logic before that injection?

@wwilsman wwilsman transferred this issue from percy/percy-agent Dec 4, 2020
@wwilsman wwilsman added the 🐛 bug Something isn't working label Dec 4, 2020
@wwilsman
Copy link
Contributor

wwilsman commented Dec 4, 2020

Hello again @nathanshelly!

I've moved this issue to the new repo since it relates directly to it.

If you can provide authorization headers via the headers option, that may also work to bypass the login screen entirely.

percy.capture({
  name: 'Behind Login',
  url: 'http://localhost:3000/protected',
  headers: {
    Authorization: 'XXXXXX'
  }
})

However, this issue did bring to my attention that if any page navigation occurs inside of the execute function, then it will also result in the error you encountered. Rather than introduce another execute option, I've opted to move the injection step to after execute is called. I also noticed there was another nuance where if the page was redirected, the incorrect URL was being provided to the snapshot method.

I've addressed both of those issues in PR #99. If you can confirm that this would solve your issue, I'll go ahead and merge it.

@nathanshelly
Copy link
Author

Whoops sorry just blindly created it in the same repo as the previous issue, thanks for moving!

That resolution sounds perfect. Thank you so much for the continued incredible support!

@nathanshelly
Copy link
Author

Following up here I was hopeful I would be able to install the latest, unreleased changes including this fix via something like this in my package.json:

"@percy/cli": "git+https://github.com/percy/cli.git#b6bceeeff58f35f379dcd2141db55259344bb3d1",

Unfortunately this fails with an error message about a missing version field. This seems to be due to a limitation of yarn with monorepo structures like this repo where it's attempting to install the top-level package.json which has no version field instead of the nested packages/cli folder that I'd need. Any chance you'd be willing to cut a new beta release so I could use the fix?

@wwilsman
Copy link
Contributor

wwilsman commented Dec 7, 2020

Sorry about the delay in releasing! I meant to do that asap, but wasn't near a computer when I merged the PR from mobile. Then my brain turned off work mode all weekend and I forgot.

I'll have a release cut shortly! 👍

@wwilsman
Copy link
Contributor

wwilsman commented Dec 7, 2020

Released 1.0.0-beta.25 🎉

@nathanshelly
Copy link
Author

No worries whatsoever, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants