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

[Credentials] Autofill when elements are in shadow #592

Merged
merged 22 commits into from
Jul 19, 2024

Conversation

dbajpeyi
Copy link
Contributor

@dbajpeyi dbajpeyi commented Jul 4, 2024

Reviewer: @shakyShane
Asana: https://app.asana.com/0/1200930669568058/1207793442006227/f

Description

Currently if a form contains elements that are within shadow root, the auto scanner misses out on all the elements of the form, and fails to categorize the inputs, although it does pierce through the shadow and find the hidden input element that was clicked on. This PR expands that a bit more:

  1. When any of the input elements are clicked, scanner tries to find the parent form (using getParentForm),
  2. getParentForm code was modified to traverse through the shadow boundary, and find the enclosing form element,
  3. The found parent form is then passed to findEligibleInputs, which was also modified to find other related inputs in the form that are hidden.

TLDR; This way essentially we do a two way scan - identify the clicked input which is in the shadow, traverse up the form and find the closest form and then build out the rest of the form from there.

Steps to test


@dbajpeyi dbajpeyi force-pushed the dbajpeyi/chase-autofill branch 6 times, most recently from eb1ad44 to d2e4907 Compare July 15, 2024 05:37
@dbajpeyi dbajpeyi changed the title wip: try parsing the whole url instead of just pathname [Credentials] Autofill when elements are in shadow Jul 15, 2024
@dbajpeyi dbajpeyi marked this pull request as ready for review July 15, 2024 05:46
@dbajpeyi dbajpeyi force-pushed the dbajpeyi/chase-autofill branch 2 times, most recently from 77ef0e3 to 366baaa Compare July 15, 2024 05:55
@dbajpeyi dbajpeyi force-pushed the dbajpeyi/chase-autofill branch 5 times, most recently from eef0b68 to 99799e4 Compare July 15, 2024 07:13
@dbajpeyi dbajpeyi force-pushed the dbajpeyi/chase-autofill branch 2 times, most recently from c79a3ee to 6c30306 Compare July 16, 2024 08:01
@dbajpeyi
Copy link
Contributor Author

dbajpeyi commented Jul 16, 2024

Thanks for the review all! Made some updates:

  1. Simplified loop: 5ec6e2a
  2. Only scan things when necessary 1c876a6 and deb7fb7
  3. Keeping track of shadow tree: 6f19720. Naming improved 460bd1c
  4. Type fix for the findEnclosedElements function 6c543b6
  5. URL evaluation improvement b321a1f

@GioSensation
Copy link
Member

My apologies, the slowdown was introduced in #574, not in this PR. It's good that we've worked through these improvements, but they were not the root cause. It's my bad, I'm sorry 😿.

I haven't reviewed the updates, I'll leave that to @shakyShane or maybe I will have some time tomorrow. While I don't think we should address the slowdown in this PR, I think we should address it before cutting a new autofill release, otherwise we risk introducing performance issues to the clients.

Copy link
Collaborator

@shakyShane shakyShane left a comment

Choose a reason for hiding this comment

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

@dbajpeyi just a couple of tiny things, otherwise this is looking really good now.

src/autofill-utils.js Outdated Show resolved Hide resolved
src/Scanner.js Outdated Show resolved Hide resolved
src/Form/Form.js Outdated Show resolved Hide resolved
@dbajpeyi
Copy link
Contributor Author

dbajpeyi commented Jul 18, 2024

@shakyShane All fixed here 2f8488c

Copy link
Member

@GioSensation GioSensation left a comment

Choose a reason for hiding this comment

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

Great work 💪 . Just a few minor things.

Comment on lines +427 to +429
// If there are not form elements, we try to look for all
// enclosed elements within the form.
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 comments should be moved 1 line below.

@@ -566,6 +566,34 @@ function getActiveElement (root = document) {
return innerActiveElement
}

/**
* Takes a root element, creates a treewalker and finds all shadow elements that match the selector
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be updated now to reflect the fact that we use querySelectorAll first.

Comment on lines -221 to +231
while (traversalLayerCount <= 5 && element.parentElement && element.parentElement !== document.documentElement) {
while (traversalLayerCount <= 5 && element.parentElement !== document.documentElement) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't quite recall why we put this here, but I do think it had a purpose. Maybe both the parentElement and the documentElement can be null in certain weird cases. I would leave it alone unless we have reason to do otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@GioSensation I've moved the condition under instead, that's why it's removed from here.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you're right. My bad.

@dbajpeyi dbajpeyi merged commit 88c8291 into main Jul 19, 2024
1 check passed
@dbajpeyi dbajpeyi deleted the dbajpeyi/chase-autofill branch July 19, 2024 08:27
CDRussell pushed a commit to duckduckgo/Android that referenced this pull request Aug 2, 2024
Task/Issue URL:
https://app.asana.com/0/1207920271697429/1207920271697429
Autofill Release:
https://github.com/duckduckgo/duckduckgo-autofill/releases/tag/12.1.0


## Description
Updates Autofill to version
[12.1.0](https://github.com/duckduckgo/duckduckgo-autofill/releases/tag/12.1.0).

### Autofill 12.1.0 release notes
## What's Changed
* [Form] Skip autofilling select input if it was changed already by
@dbajpeyi in duckduckgo/duckduckgo-autofill#580
* scanner: discard Form instances with no classified inputs by @sjbarag
in duckduckgo/duckduckgo-autofill#574
* [Credentials] Autofill when elements are in shadow by @dbajpeyi in
duckduckgo/duckduckgo-autofill#592
* Update password-related json files (2024-07-19) by @daxmobile in
duckduckgo/duckduckgo-autofill#607
* [Scanner] Don't stop scanner fully on max forms by @dbajpeyi in
duckduckgo/duckduckgo-autofill#617
* tests: remove spurious logging from unit tests by @sjbarag in
duckduckgo/duckduckgo-autofill#575
* Add credit card test form failure by @GioSensation in
duckduckgo/duckduckgo-autofill#588

## New Contributors
* @dbajpeyi made their first contribution in
duckduckgo/duckduckgo-autofill#580

**Full Changelog**:
duckduckgo/duckduckgo-autofill@12.0.1...12.1.0

## Steps to test
This release has been tested during autofill development. For smoke test
steps see [this
task](https://app.asana.com/0/1198964220583541/1200583647142330/f).

Co-authored-by: GioSensation <1828326+GioSensation@users.noreply.github.com>
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

3 participants