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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip: add a chase like form (shadow elements in iframe)
  • Loading branch information
dbajpeyi committed Jul 11, 2024
commit 91c4a8f7a06bfe2cd64d62eee5bf356a3379c1db
12 changes: 5 additions & 7 deletions dist/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions dist/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions integration-test/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<li><a href="login-poor-form.html">login-poor-form.html</a></li>
<li><a href="signup.html">signup.html</a></li>
<li><a href="select-input.html">select-input.html</a></li>
<li><a href="shadow-in-iframe/form.html">shadow-in-iframe/form.html</a></li>
</ul>
</body>
</html>
11 changes: 11 additions & 0 deletions integration-test/pages/shadow-in-iframe/form-in-iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Shadow Elements Example</title>
<p>The following form is embedded in an iframe</p>
</head>
<body>
<h1>Shadow Elements Example</h1>
<iframe src="shadow-elements.html" width="100%" height="400"></iframe>
</body>
</html>
48 changes: 48 additions & 0 deletions integration-test/pages/shadow-in-iframe/shadow-elements.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<title>Shadow DOM Form</title>
</head>
<body>
<p>Replicating secure.chase.com: each of the following form elements are within a shadow root that is open.
The form element itself is not in a shadow root
</p>
<form>
<div id="usernameRoot"></div>
<div id="passwordRoot"></div>
<div id="submitRoot" type="submit">Sign up</div>
</form>

<script>
// Create shadow roots for username and password inputs
const usernameRoot = document.getElementById('usernameRoot').attachShadow({ mode: 'open' });
const passwordRoot = document.getElementById('passwordRoot').attachShadow({ mode: 'open' });
const submitRoot = document.getElementById('submitRoot').attachShadow({ mode: 'open' });

// Create username input element
const usernameInput = document.createElement('input');
usernameInput.type = 'text';
usernameInput.placeholder = 'Username';
usernameRoot.appendChild(usernameInput);

// Create password input element
const passwordInput = document.createElement('input');
passwordInput.type = 'password';
passwordInput.placeholder = 'Password';
passwordRoot.appendChild(passwordInput);

// Create a submit button
const submitButton = document.createElement('button');
submitButton.textContent = 'Submit';
submitRoot.appendChild(submitButton);

// Add event listener to submit button
submitButton.addEventListener('click', function(event) {
event.preventDefault();
alert('Username: ' + usernameInput.value + '\nPassword: ' + passwordInput.value);
});

</script>

</body>
</html>
12 changes: 5 additions & 7 deletions src/Scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,26 @@
logPerformance('initial_scanner')
this.mutObs.observe(document.documentElement, { childList: true, subtree: true })
}

Check failure on line 143 in src/Scanner.js

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed

Check failure on line 144 in src/Scanner.js

View workflow job for this annotation

GitHub Actions / test

More than 1 blank line not allowed

// Function to find shadow roots in the document
findShadowRoots(node) {

Check failure on line 147 in src/Scanner.js

View workflow job for this annotation

GitHub Actions / test

Missing space before function parentheses
const shadowRoots = [];

Check failure on line 148 in src/Scanner.js

View workflow job for this annotation

GitHub Actions / test

Extra semicolon

// Recursive function to traverse the DOM
function traverse(node) {

Check failure on line 151 in src/Scanner.js

View workflow job for this annotation

GitHub Actions / test

Missing space before function parentheses
// Check if the node has a shadow root
if (node.shadowRoot) {
shadowRoots.push(node.shadowRoot);

Check failure on line 154 in src/Scanner.js

View workflow job for this annotation

GitHub Actions / test

Extra semicolon
}

// Traverse child nodes
node.childNodes.forEach(child => traverse(child));

Check failure on line 158 in src/Scanner.js

View workflow job for this annotation

GitHub Actions / test

Extra semicolon

// Traverse shadow DOM if exists
if (node.shadowRoot) {
node.shadowRoot.childNodes.forEach(child => traverse(child));

Check failure on line 162 in src/Scanner.js

View workflow job for this annotation

GitHub Actions / test

Extra semicolon
}
}

Expand Down Expand Up @@ -216,11 +216,11 @@
console.log("DEEP adding whole context as input", context)
this.addInput(context)
} else {
// const inputs = context.querySelectorAll(this.matching.cssSelector('formInputsSelectorWithoutSelect'))
const shadowRoots = this.findAllShadowHosts()
console.log("DEEP shadowRoots", shadowRoots)
const inputs = this.findInputsInShadowRoots(shadowRoots);
console.log("DEEP inputs", inputs)
const inputs = context.querySelectorAll(this.matching.cssSelector('formInputsSelectorWithoutSelect'))
// const shadowRoots = this.findAllShadowHosts()
// console.log("DEEP shadowRoots", shadowRoots)
// const inputs = this.findInputsInShadowRoots(shadowRoots);
// console.log("DEEP inputs", inputs)
if (inputs.length > this.options.maxInputsPerPage) {
this.stopScanner(`Too many input fields in the given context (${inputs.length}), stop scanning`, context)
return this
Expand Down Expand Up @@ -314,7 +314,6 @@
if (this.stopped) return

const parentForm = this.getParentForm(input)
console.log("DEEP parent form", parentForm);

if (parentForm instanceof HTMLFormElement && this.forms.has(parentForm)) {
const foundForm = this.forms.get(parentForm)
Expand Down Expand Up @@ -412,7 +411,6 @@
*/
processChangedElements () {
if (this.rescanAll) {
console.log('DEEP rescan all')
this.findEligibleInputs(document)
return
}
Expand Down
12 changes: 5 additions & 7 deletions swift-package/Resources/assets/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions swift-package/Resources/assets/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading