Skip to content

Commit

Permalink
- Switch to session storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantin-msft committed Dec 5, 2023
1 parent ab04f27 commit 79a5590
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"type": "patch",
"comment": "Allow overriding log level and PII setting with local storage key-values #6704",
"comment": "Allow overriding log level and PII setting with session storage key-values #6704",
"packageName": "@azure/msal-browser",
"email": "[email protected]",
"dependentChangeType": "patch"
Expand Down
12 changes: 5 additions & 7 deletions lib/msal-browser/docs/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,20 @@ An example usage in a sample can be accessed [here](https://github.com/AzureAD/m

These are the steps to override MSAL log level and PII settings to troubleshoot errors in non-dev environments:

### Navigate to local storage
### Navigate to session storage

1. Open developer tools by pressing F12
2. Navigate to `Application` tab
3. Click `Storage` and expand `Local Storage`
3. Click `Storage` and expand `Session Storage`
4. Select target domain

Additional details can be found [here](https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/storage/localstorage).
Additional details can be found [here](https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/storage/sessionstorage).

### Override log level

Add `msal.browser.log.level` key to `Local Storage`, set it's value to the desired log level (`Verbose`, for example) and refresh the page.
Add `msal.browser.log.level` key to `Session Storage`, set it's value to the desired log level (`Verbose`, for example) and refresh the page.
Check `LogLevel` enum for the available options [here](../../msal-common/src/logger/Logger.ts).

### Override PII log setting

Add `msal.browser.log.pii` key to `Local Storage`, set it's value to `true` or `false` and refresh the page.

**_NOTE:_** Make sure to remove the log keys from `Local Storage` once troubleshooting is done.
Add `msal.browser.log.pii` key to `Session Storage`, set it's value to `true` or `false` and refresh the page.
9 changes: 5 additions & 4 deletions lib/msal-browser/src/operatingcontext/BaseOperatingContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ export abstract class BaseOperatingContext {
this.browserEnvironment = typeof window !== "undefined";
this.config = buildConfiguration(config, this.browserEnvironment);

let localStorage: Storage | undefined;
let sessionStorage: Storage | undefined;
try {
localStorage = window[BrowserCacheLocation.LocalStorage];
sessionStorage = window[BrowserCacheLocation.SessionStorage];
// Mute errors if it's a non-browser environment or cookies are blocked.
} catch (e) {}

const logLevelKey = localStorage?.getItem(LOG_LEVEL_CACHE_KEY);
const logLevelKey = sessionStorage?.getItem(LOG_LEVEL_CACHE_KEY);
const piiLoggingEnabled =
localStorage?.getItem(LOG_PII_CACHE_KEY)?.toLowerCase() === "true";
sessionStorage?.getItem(LOG_PII_CACHE_KEY)?.toLowerCase() ===
"true";

if (logLevelKey || piiLoggingEnabled) {
const logLevel =
Expand Down

0 comments on commit 79a5590

Please sign in to comment.