Skip to content

Commit

Permalink
feat(bitwarden): errors from loadSuggestions in getSuggestions ar…
Browse files Browse the repository at this point in the history
…e now thrown directly

fix(passwordCapture): renamed typo `handleRecieveCredentials` to `handleReceivedCredentials` and updated usage
refactor(passwordCapture): updated error handling for `getSuggestions` in `handleReceivedCredentials`
  • Loading branch information
UnKnoWn-Consortium committed May 29, 2023
1 parent 2790375 commit 105c09d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
9 changes: 1 addition & 8 deletions js/passwordManager/bitwarden.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,7 @@ class Bitwarden {
throw new Error()
}

try {
const suggestions = await this.loadSuggestions(command, domain)
this.lastCallList[domain] = suggestions
return suggestions
} catch (e) {
this.lastCallList[domain] = null
}

this.lastCallList[domain] = await this.loadSuggestions(command, domain)
return this.lastCallList[domain]
}

Expand Down
40 changes: 22 additions & 18 deletions js/passwordManager/passwordCapture.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const passwordCapture = {
}
},

async handleRecieveCredentials (tab, args, frameId) {
async handleReceivedCredentials (tab, args, frameId) {
let domain = args[0][0]
if (domain.startsWith('www.')) {
domain = domain.slice(4)
Expand All @@ -60,33 +60,37 @@ const passwordCapture = {
return
}

const username = args[0][1] || ''
const password = args[0][2] || ''
try {
const username = args[0][1] || ''
const password = args[0][2] || ''

const manager = await PasswordManagers.getConfiguredPasswordManager()
if (!manager || !manager.saveCredential) {
// the password can't be saved
return
}

// check if this username/password combo is already saved
const credentials = await manager.getSuggestions(domain)
const alreadyExists = credentials.some(cred => cred.username === username && cred.password === password)
if (!alreadyExists) {
if (!passwordCapture.bar.hidden) {
passwordCapture.hideCaptureBar()
const manager = await PasswordManagers.getConfiguredPasswordManager()
if (!manager || !manager.saveCredential) {
// the password can't be saved
return
}

passwordCapture.currentDomain = domain
passwordCapture.showCaptureBar(username, password)
// check if this username/password combo is already saved
const credentials = await manager.getSuggestions(domain)
const alreadyExists = credentials.some(cred => cred.username === username && cred.password === password)
if (!alreadyExists) {
if (!passwordCapture.bar.hidden) {
passwordCapture.hideCaptureBar()
}

passwordCapture.currentDomain = domain
passwordCapture.showCaptureBar(username, password)
}
} catch (e) {
console.error(`Failed to get password suggestions: ${e.message}`)
}
},

initialize () {
passwordCapture.usernameInput.placeholder = l('username')
passwordCapture.passwordInput.placeholder = l('password')

webviews.bindIPC('password-form-filled', passwordCapture.handleRecieveCredentials)
webviews.bindIPC('password-form-filled', passwordCapture.handleReceivedCredentials)

passwordCapture.saveButton.addEventListener('click', function () {
if (passwordCapture.usernameInput.checkValidity() && passwordCapture.passwordInput.checkValidity()) {
Expand Down
2 changes: 1 addition & 1 deletion js/passwordManager/passwordManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function initialize () {

try {
const credentials = await manager.getSuggestions(hostname)
if (credentials !== null) {
if (credentials) {
webviews.callAsync(tab, 'sendToFrame', [frameId, 'password-autofill-match', {
credentials,
hostname
Expand Down

0 comments on commit 105c09d

Please sign in to comment.