1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-06-20 09:35:22 +02:00

[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:
Jonathan Prusik 2023-08-15 09:28:05 -04:00 committed by GitHub
parent 1046cac33c
commit 3a2d89c948
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 100 additions and 51 deletions

View File

@ -3,6 +3,7 @@ import ChangePasswordRuntimeMessage from "../../background/models/changePassword
import AutofillField from "../models/autofill-field";
import { WatchedForm } from "../models/watched-form";
import { FormData } from "../services/abstractions/autofill.service";
import { UserSettings } from "../types";
interface HTMLElementWithFormOpId extends HTMLElement {
formOpId: string;
@ -26,10 +27,64 @@ interface HTMLElementWithFormOpId extends HTMLElement {
* and async scripts to finish loading.
* https://developer.mozilla.org/en-US/docs/Web/API/Window/DOMContentLoaded_event
*/
document.addEventListener("DOMContentLoaded", (event) => {
// Do not show the notification bar on the Bitwarden vault
// because they can add logins and change passwords there
if (window.location.hostname.endsWith("vault.bitwarden.com")) {
document.addEventListener("DOMContentLoaded", async (event) => {
// 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;
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;
}
@ -77,53 +132,6 @@ document.addEventListener("DOMContentLoaded", (event) => {
]);
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
// Listen for messages from the background script

View File

@ -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;
};