Skip to content

Commit

Permalink
feat: Add option to autofill only one field
Browse files Browse the repository at this point in the history
By passing an html ID in doAutoFill, we can now autofill only one
field.
  • Loading branch information
zatteo committed Jul 24, 2024
1 parent 6b876ca commit d1677ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/browser/src/autofill/background/overlay.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ export class OverlayBackground implements OverlayBackgroundInterface {
pageDetails: Array.from(pageDetails.values()),
fillNewPassword: true,
allowTotpAutofill: true,
fillOnlyThisFieldHtmlID: "full-name",
});

// Cozy customization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface AutoFillOptions {
allowTotpAutofill?: boolean;
// Cozy customization
cozyProfile?: CozyProfile;
fillOnlyThisFieldHtmlID?: string;
// Cozy customization end
}

Expand All @@ -60,6 +61,7 @@ export interface GenerateFillScriptOptions {
defaultUriMatch: UriMatchStrategySetting;
// Cozy customization
cozyProfile?: CozyProfile;
fillOnlyThisFieldHtmlID?: string;
// Cozy customization end
}

Expand Down
13 changes: 13 additions & 0 deletions apps/browser/src/autofill/services/autofill.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ export default class AutofillService implements AutofillServiceInterface {
tabUrl: tab.url,
defaultUriMatch: defaultUriMatch,
cozyProfile: options.cozyProfile, // Cozy customization
fillOnlyThisFieldHtmlID: options.fillOnlyThisFieldHtmlID, // Cozy customization
});

if (!fillScript || !fillScript.script || !fillScript.script.length) {
Expand Down Expand Up @@ -585,6 +586,18 @@ export default class AutofillService implements AutofillServiceInterface {
return null;
}

// Cozy customization; autofill only one field
if (options.fillOnlyThisFieldHtmlID) {
pageDetails = {
...pageDetails,
fields: pageDetails.fields.filter(
(field) => field.htmlID === options.fillOnlyThisFieldHtmlID,
),
};
}

// Cozy customization end

let fillScript = new AutofillScript();
const filledFields: { [id: string]: AutofillField } = {};
const fields = options.cipher.fields;
Expand Down

0 comments on commit d1677ef

Please sign in to comment.