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

enabled web-vitals-extension loggin option #80

Merged
merged 2 commits into from
Nov 17, 2020
Merged
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
14 changes: 13 additions & 1 deletion src/browser_action/vitals.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
const webVitals = await import(src);
let overlayClosedForSession = false;
let latestCLS = {};
let enableLogging = localStorage.getItem('web-vitals-extension-debug')=='TRUE';

// Core Web Vitals thresholds
const LCP_THRESHOLD = 2500;
Expand Down Expand Up @@ -87,8 +88,9 @@
// Check for preferences set in options
chrome.storage.sync.get({
enableOverlay: false,
debug: false,
}, ({
enableOverlay,
enableOverlay, debug,
}) => {
if (enableOverlay === true && overlayClosedForSession == false) {
// Overlay
Expand Down Expand Up @@ -124,6 +126,13 @@
});
}
}
if (debug) {
localStorage.setItem('web-vitals-extension-debug', 'TRUE');
enableLogging = true;
} else {
localStorage.removeItem('web-vitals-extension-debug');
enableLogging = false;
}
});
}

Expand Down Expand Up @@ -159,6 +168,9 @@
if (metricName === undefined || badgeMetrics === undefined) {
return;
}
if (enableLogging) {
console.log('[Web Vitals]', body.name, body.value.toFixed(2), body);
}
badgeMetrics[metricName].value = body.value;
badgeMetrics[metricName].final = body.isFinal;
badgeMetrics.location = getURL();
Expand Down
5 changes: 5 additions & 0 deletions src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<input type="checkbox" id="overlay">
Display HUD overlay
</label>
<br/>
<label>
<input type="checkbox" id="consoleLogging">
Console Logging
</label>
<div id="status"></div>
<button id="save">Save</button>
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/options/options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const optionsOverlayNode = document.getElementById('overlay');
const optionsConsoleLoggingNode = document.getElementById('consoleLogging');
const optionsSaveBtn = document.getElementById('save');
const optionsStatus = document.getElementById('status');

Expand All @@ -8,6 +9,7 @@ const optionsStatus = document.getElementById('status');
function saveOptions() {
chrome.storage.sync.set({
enableOverlay: optionsOverlayNode.checked,
debug: optionsConsoleLoggingNode.checked,
}, () => {
// Update status to let user know options were saved.
optionsStatus.textContent = 'Options saved.';
Expand All @@ -24,8 +26,10 @@ function saveOptions() {
function restoreOptions() {
chrome.storage.sync.get({
enableOverlay: false,
}, ({enableOverlay}) => {
debug: false,
}, ({enableOverlay, debug}) => {
optionsOverlayNode.checked = enableOverlay;
optionsConsoleLoggingNode.checked = debug;
});
}
document.addEventListener('DOMContentLoaded', restoreOptions);
Expand Down