Skip to content

Commit

Permalink
Revert mutation observer for forms (#396)
Browse files Browse the repository at this point in the history
GioSensation authored Oct 10, 2023
1 parent 25176a5 commit 6dd7d69
Showing 7 changed files with 36 additions and 177 deletions.
42 changes: 7 additions & 35 deletions dist/autofill-debug.js

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

42 changes: 7 additions & 35 deletions dist/autofill.js

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

2 changes: 1 addition & 1 deletion integration-test/tests/mutating-form.macos.spec.js
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import {test as base} from '@playwright/test'
*/
const test = base.extend({})

test.describe('Mutating form page', () => {
test.describe.skip('Mutating form page', () => {
async function applyScript (page) {
await createAutofillScript()
.replaceAll(macosContentScopeReplacements())
34 changes: 0 additions & 34 deletions src/Form/Form.js
Original file line number Diff line number Diff line change
@@ -26,7 +26,6 @@ import {constants} from '../constants.js'
const {
ATTR_AUTOFILL,
ATTR_INPUT_TYPE,
MAX_FORM_MUT_OBS_COUNT,
MAX_INPUTS_PER_FORM
} = constants

@@ -77,30 +76,6 @@ class Form {
}
})

this.mutObsCount = 0
this.mutObsConfig = { childList: true, subtree: true }
this.mutObs = new MutationObserver(
(records) => {
const anythingRemoved = records.some(record => record.removedNodes.length > 0)
if (anythingRemoved) {
// Must check for inputs because a parent may be removed and not show up in record.removedNodes
if ([...this.inputs.all].some(input => !input.isConnected)) {
// If any known input has been removed from the DOM, reanalyze the whole form
window.requestIdleCallback(() => {
this.formAnalyzer = new FormAnalyzer(this.form, input, this.matching)
this.recategorizeAllInputs()
})

this.mutObsCount++
// If the form mutates too much, disconnect to avoid performance issues
if (this.mutObsCount >= MAX_FORM_MUT_OBS_COUNT) {
this.mutObs.disconnect()
}
}
}
}
)

// This ensures we fire the handler again if the form is changed
this.addListener(form, 'input', () => {
if (!this.isAutofilling) {
@@ -110,7 +85,6 @@ class Form {
})

this.categorizeInputs()
this.mutObs.observe(this.form, this.mutObsConfig)

this.logFormInfo()

@@ -356,7 +330,6 @@ class Form {
this.removeAllDecorations()
this.removeTooltip()
this.forgetAllInputs()
this.mutObs.disconnect()
this.matching.clear()
this.intObs = null
}
@@ -444,13 +417,6 @@ class Form {
return this
}

// When new inputs are added after the initial scan, reanalyze the whole form
if (this.initialScanComplete) {
this.formAnalyzer = new FormAnalyzer(this.form, input, this.matching)
this.recategorizeAllInputs()
return this
}

// Nothing to do with 1-character fields
if (input.maxLength === 1) return this

9 changes: 7 additions & 2 deletions src/Scanner.js
Original file line number Diff line number Diff line change
@@ -226,8 +226,13 @@ class DefaultScanner {
const parentForm = this.getParentForm(input)

if (parentForm instanceof HTMLFormElement && this.forms.has(parentForm)) {
// We've met the form, add the input
this.forms.get(parentForm)?.addInput(input)
const foundForm = this.forms.get(parentForm)
// We've met the form, add the input provided it's below the max input limit
if (foundForm && foundForm.inputs.all.size < MAX_INPUTS_PER_FORM) {
foundForm.addInput(input)
} else {
this.stopScanner('The form has too many inputs, destroying.')
}
return
}

42 changes: 7 additions & 35 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.

Loading

0 comments on commit 6dd7d69

Please sign in to comment.