[PM-2597] Do not show the notification banner on the configured bitwarden vault domain (#5863)
* ignore TLD when checking for no banner display on a vault page * do not show the notification banner on the configured bitwarden vault domain * add types
This commit is contained in:
parent
1046cac33c
commit
3a2d89c948
|
@ -3,6 +3,7 @@ import ChangePasswordRuntimeMessage from "../../background/models/changePassword
|
||||||
import AutofillField from "../models/autofill-field";
|
import AutofillField from "../models/autofill-field";
|
||||||
import { WatchedForm } from "../models/watched-form";
|
import { WatchedForm } from "../models/watched-form";
|
||||||
import { FormData } from "../services/abstractions/autofill.service";
|
import { FormData } from "../services/abstractions/autofill.service";
|
||||||
|
import { UserSettings } from "../types";
|
||||||
|
|
||||||
interface HTMLElementWithFormOpId extends HTMLElement {
|
interface HTMLElementWithFormOpId extends HTMLElement {
|
||||||
formOpId: string;
|
formOpId: string;
|
||||||
|
@ -26,10 +27,64 @@ interface HTMLElementWithFormOpId extends HTMLElement {
|
||||||
* and async scripts to finish loading.
|
* and async scripts to finish loading.
|
||||||
* https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
|
* https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
|
||||||
*/
|
*/
|
||||||
document.addEventListener("DOMContentLoaded", (event) => {
|
document.addEventListener("DOMContentLoaded", async (event) => {
|
||||||
// Do not show the notification bar on the Bitwarden vault
|
// These are preferences for whether to show the notification bar based on the user's settings
|
||||||
// because they can add logins and change passwords there
|
// and they are set in the Settings > Options page in the browser extension.
|
||||||
if (window.location.hostname.endsWith("vault.bitwarden.com")) {
|
let disabledAddLoginNotification = false;
|
||||||
|
let disabledChangedPasswordNotification = false;
|
||||||
|
let showNotificationBar = true;
|
||||||
|
|
||||||
|
// Look up the active user id from storage
|
||||||
|
const activeUserIdKey = "activeUserId";
|
||||||
|
let activeUserId: string;
|
||||||
|
await chrome.storage.local.get(activeUserIdKey, (obj: any) => {
|
||||||
|
if (obj == null || obj[activeUserIdKey] == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
activeUserId = obj[activeUserIdKey];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Look up the user's settings from storage
|
||||||
|
await chrome.storage.local.get(activeUserId, (obj: any) => {
|
||||||
|
if (obj?.[activeUserId] == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const userSettings: UserSettings = obj[activeUserId].settings;
|
||||||
|
|
||||||
|
// Do not show the notification bar on the Bitwarden vault
|
||||||
|
// because they can add logins and change passwords there
|
||||||
|
if (window.location.origin === userSettings.serverConfig.environment.vault) {
|
||||||
|
showNotificationBar = false;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// NeverDomains is a dictionary of domains that the user has chosen to never
|
||||||
|
// show the notification bar on (for login detail collection or password change).
|
||||||
|
// It is managed in the Settings > Excluded Domains page in the browser extension.
|
||||||
|
// Example: '{"bitwarden.com":null}'
|
||||||
|
const excludedDomainsDict = userSettings.neverDomains;
|
||||||
|
|
||||||
|
if (
|
||||||
|
excludedDomainsDict != null &&
|
||||||
|
// eslint-disable-next-line
|
||||||
|
excludedDomainsDict.hasOwnProperty(window.location.hostname)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set local disabled preferences
|
||||||
|
disabledAddLoginNotification = userSettings.disableAddLoginNotification;
|
||||||
|
disabledChangedPasswordNotification = userSettings.disableChangedPasswordNotification;
|
||||||
|
|
||||||
|
if (!disabledAddLoginNotification || !disabledChangedPasswordNotification) {
|
||||||
|
// If the user has not disabled both notifications, then handle the initial page change (null -> actual page)
|
||||||
|
handlePageChange();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!showNotificationBar) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,53 +132,6 @@ document.addEventListener("DOMContentLoaded", (event) => {
|
||||||
]);
|
]);
|
||||||
const changePasswordButtonContainsNames = new Set(["pass", "change", "contras", "senha"]);
|
const changePasswordButtonContainsNames = new Set(["pass", "change", "contras", "senha"]);
|
||||||
|
|
||||||
// These are preferences for whether to show the notification bar based on the user's settings
|
|
||||||
// and they are set in the Settings > Options page in the browser extension.
|
|
||||||
let disabledAddLoginNotification = false;
|
|
||||||
let disabledChangedPasswordNotification = false;
|
|
||||||
|
|
||||||
// Look up the active user id from storage
|
|
||||||
const activeUserIdKey = "activeUserId";
|
|
||||||
let activeUserId: string;
|
|
||||||
chrome.storage.local.get(activeUserIdKey, (obj: any) => {
|
|
||||||
if (obj == null || obj[activeUserIdKey] == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
activeUserId = obj[activeUserIdKey];
|
|
||||||
});
|
|
||||||
|
|
||||||
// Look up the user's settings from storage
|
|
||||||
chrome.storage.local.get(activeUserId, (obj: any) => {
|
|
||||||
if (obj?.[activeUserId] == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const userSettings = obj[activeUserId].settings;
|
|
||||||
|
|
||||||
// NeverDomains is a dictionary of domains that the user has chosen to never
|
|
||||||
// show the notification bar on (for login detail collection or password change).
|
|
||||||
// It is managed in the Settings > Excluded Domains page in the browser extension.
|
|
||||||
// Example: '{"bitwarden.com":null}'
|
|
||||||
const excludedDomainsDict = userSettings.neverDomains;
|
|
||||||
|
|
||||||
if (
|
|
||||||
excludedDomainsDict != null &&
|
|
||||||
// eslint-disable-next-line
|
|
||||||
excludedDomainsDict.hasOwnProperty(window.location.hostname)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set local disabled preferences
|
|
||||||
disabledAddLoginNotification = userSettings.disableAddLoginNotification;
|
|
||||||
disabledChangedPasswordNotification = userSettings.disableChangedPasswordNotification;
|
|
||||||
|
|
||||||
if (!disabledAddLoginNotification || !disabledChangedPasswordNotification) {
|
|
||||||
// If the user has not disabled both notifications, then handle the initial page change (null -> actual page)
|
|
||||||
handlePageChange();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Message Processing
|
// Message Processing
|
||||||
|
|
||||||
// Listen for messages from the background script
|
// Listen for messages from the background script
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
import { Region } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||||
|
import { VaultTimeoutAction } from "@bitwarden/common/src/enums/vault-timeout-action.enum";
|
||||||
|
|
||||||
|
export type UserSettings = {
|
||||||
|
avatarColor: string | null;
|
||||||
|
environmentUrls: {
|
||||||
|
api: string | null;
|
||||||
|
base: string | null;
|
||||||
|
events: string | null;
|
||||||
|
icons: string | null;
|
||||||
|
identity: string | null;
|
||||||
|
keyConnector: string | null;
|
||||||
|
notifications: string | null;
|
||||||
|
webVault: string | null;
|
||||||
|
};
|
||||||
|
pinProtected: { [key: string]: any };
|
||||||
|
region: Region;
|
||||||
|
serverConfig: {
|
||||||
|
environment: {
|
||||||
|
api: string | null;
|
||||||
|
cloudRegion: string | null;
|
||||||
|
identity: string | null;
|
||||||
|
notifications: string | null;
|
||||||
|
sso: string | null;
|
||||||
|
vault: string | null;
|
||||||
|
};
|
||||||
|
featureStates: { [key: string]: any };
|
||||||
|
gitHash: string;
|
||||||
|
server: { [key: string]: any };
|
||||||
|
utcDate: string;
|
||||||
|
version: string;
|
||||||
|
};
|
||||||
|
settings: {
|
||||||
|
equivalentDomains: string[][];
|
||||||
|
};
|
||||||
|
neverDomains?: { [key: string]: any };
|
||||||
|
disableAddLoginNotification?: boolean;
|
||||||
|
disableChangedPasswordNotification?: boolean;
|
||||||
|
vaultTimeout: number;
|
||||||
|
vaultTimeoutAction: VaultTimeoutAction;
|
||||||
|
};
|
Loading…
Reference in New Issue