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

Add feature: highlight the form fields Browserpass will fill #341

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 22 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ chrome.browserAction.setBadgeBackgroundColor({
});

// watch for tab updates
chrome.tabs.onUpdated.addListener((tabId, info) => {
chrome.tabs.onUpdated.addListener(async (tabId, info) => {
// unregister any auth listeners for this tab
if (info.status === "complete") {
if (authListeners[tabId]) {
Expand All @@ -53,7 +53,25 @@ chrome.tabs.onUpdated.addListener((tabId, info) => {
}

// redraw badge counter
updateMatchingPasswordsCount(tabId);
let matchCount = await updateMatchingPasswordsCount(tabId);

// highlight the default login & secret fields
if (matchCount) {
try {
await chrome.tabs.executeScript(tabId, {
allFrames: true,
file: "js/inject.dist.js",
});
await chrome.tabs.executeScript(tabId, {
allFrames: true,
code: `window.browserpass.highlightLoginFields();`,
});
} catch (e) {
// errors here mean that the browser denied the script injection, typically
// because the tab is not allowed to run content scripts (e.g. chrome://
// pages etc). We can safely ignore these errors.
}
}
});

// handle incoming messages
Expand Down Expand Up @@ -155,6 +173,8 @@ async function updateMatchingPasswordsCount(tabId, forceRefresh = false) {
text: "" + (matchedPasswordsCount || ""),
tabId: tabId,
});

return matchedPasswordsCount;
} catch (e) {
console.log(e);
}
Expand Down
18 changes: 18 additions & 0 deletions src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@
],
};

/**
* Highlight fields to be filled for login & password
*
* @since 3.8.1
*
* @return void
*/
function highlightLoginFields() {
let loginForm = form(INPUT_FIELDS),
login = find(USERNAME_FIELDS, loginForm),
secret = find(PASSWORD_FIELDS, loginForm),
openid = find(OPENID_FIELDS, loginForm);
if (login) login.style.outline = "2px solid #1A7B84";
if (secret) secret.style.outline = "2px solid #1A7B84";
if (openid) openid.style.outline = "2px solid #1A7B84";
}

/**
* Fill password
*
Expand Down Expand Up @@ -498,5 +515,6 @@
window.browserpass = {
fillLogin: fillLogin,
focusOrSubmit: focusOrSubmit,
highlightLoginFields: highlightLoginFields,
};
})();