Skip to content

Commit

Permalink
wip: add a chase like form (shadow elements in iframe)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Jul 11, 2024
1 parent 5edc95f commit 91c4a8f
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 35 deletions.
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 @@ -216,11 +216,11 @@ class DefaultScanner {
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 @@ class DefaultScanner {
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 @@ class DefaultScanner {
*/
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.

0 comments on commit 91c4a8f

Please sign in to comment.