Add way to copy debug logs from popup

This commit is contained in:
Ajay 2024-09-08 01:20:25 -04:00
parent 2a2896786c
commit 12e8c7aad8
7 changed files with 58 additions and 30 deletions

@ -1 +1 @@
Subproject commit 7cedce215851872be28bd50a9f690b680dd54442 Subproject commit 3c5a80ca9cc600c7c03b8d513cd80df8aa17b240

View file

@ -196,6 +196,8 @@
<a href="https://discord.gg/SponsorBlock" target="_blank" rel="noopener">Discord</a> <a href="https://discord.gg/SponsorBlock" target="_blank" rel="noopener">Discord</a>
<a href="https://matrix.to/#/#sponsor:ajay.app?via=ajay.app&via=matrix.org&via=mozilla.org" target="_blank" rel="noopener">Matrix</a> <a href="https://matrix.to/#/#sponsor:ajay.app?via=ajay.app&via=matrix.org&via=mozilla.org" target="_blank" rel="noopener">Matrix</a>
<a href="https://sponsor.ajay.app/donate" target="_blank" rel="noopener" id="sbDonate">__MSG_Donate__</a> <a href="https://sponsor.ajay.app/donate" target="_blank" rel="noopener" id="sbDonate">__MSG_Donate__</a>
<br />
<a id="debugLogs">__MSG_copyDebugLogs__</a>
</footer> </footer>
<button id="showNoticeAgain" style="display: none">__MSG_showNotice__</button> <button id="showNoticeAgain" style="display: none">__MSG_showNotice__</button>

View file

@ -477,4 +477,26 @@ const localDefaults = {
}; };
const Config = new ConfigClass(syncDefaults, localDefaults, migrateOldSyncFormats); const Config = new ConfigClass(syncDefaults, localDefaults, migrateOldSyncFormats);
export default Config; export default Config;
export function generateDebugDetails(): string {
// Build output debug information object
const output = {
debug: {
userAgent: navigator.userAgent,
platform: navigator.platform,
language: navigator.language,
extensionVersion: chrome.runtime.getManifest().version
},
config: JSON.parse(JSON.stringify(Config.cachedSyncConfig)) // Deep clone config object
};
// Sanitise sensitive user config values
delete output.config.userID;
output.config.serverAddress = (output.config.serverAddress === CompileConfig.serverAddress)
? "Default server address" : "Custom server address";
output.config.invidiousInstances = output.config.invidiousInstances.length;
output.config.whitelistedChannels = output.config.whitelistedChannels.length;
return JSON.stringify(output, null, 4);
}

View file

@ -346,6 +346,12 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
metaKey: request.metaKey metaKey: request.metaKey
})); }));
break; break;
case "getLogs":
sendResponse({
debug: window["SBLogs"].debug,
warn: window["SBLogs"].warn
});
break;
} }
sendResponse({}); sendResponse({});

View file

@ -17,7 +17,8 @@ interface DefaultMessage {
| "isChannelWhitelisted" | "isChannelWhitelisted"
| "submitTimes" | "submitTimes"
| "refreshSegments" | "refreshSegments"
| "closePopup"; | "closePopup"
| "getLogs";
} }
interface BoolValueMessage { interface BoolValueMessage {
@ -104,7 +105,8 @@ export type MessageResponse =
| Record<string, never> // empty object response {} | Record<string, never> // empty object response {}
| VoteResponse | VoteResponse
| ImportSegmentsResponse | ImportSegmentsResponse
| RefreshSegmentsResponse; | RefreshSegmentsResponse
| LogResponse;
export interface VoteResponse { export interface VoteResponse {
successType: number; successType: number;
@ -120,6 +122,11 @@ export interface RefreshSegmentsResponse {
hasVideo: boolean; hasVideo: boolean;
} }
export interface LogResponse {
debug: string[];
warn: string[];
}
export interface TimeUpdateMessage { export interface TimeUpdateMessage {
message: "time"; message: "time";
time: number; time: number;

View file

@ -1,7 +1,7 @@
import * as React from "react"; import * as React from "react";
import { createRoot } from 'react-dom/client'; import { createRoot } from 'react-dom/client';
import Config from "./config"; import Config, { generateDebugDetails } from "./config";
import * as CompileConfig from "../config.json"; import * as CompileConfig from "../config.json";
import * as invidiousList from "../ci/invidiouslist.json"; import * as invidiousList from "../ci/invidiouslist.json";
@ -698,32 +698,14 @@ function validateServerAddress(input: string): string {
} }
function copyDebugOutputToClipboard() { function copyDebugOutputToClipboard() {
// Build output debug information object
const output = {
debug: {
userAgent: navigator.userAgent,
platform: navigator.platform,
language: navigator.language,
extensionVersion: chrome.runtime.getManifest().version
},
config: JSON.parse(JSON.stringify(Config.cachedSyncConfig)) // Deep clone config object
};
// Sanitise sensitive user config values
delete output.config.userID;
output.config.serverAddress = (output.config.serverAddress === CompileConfig.serverAddress)
? "Default server address" : "Custom server address";
output.config.invidiousInstances = output.config.invidiousInstances.length;
output.config.whitelistedChannels = output.config.whitelistedChannels.length;
// Copy object to clipboard // Copy object to clipboard
navigator.clipboard.writeText(JSON.stringify(output, null, 4)) navigator.clipboard.writeText(generateDebugDetails())
.then(() => { .then(() => {
alert(chrome.i18n.getMessage("copyDebugInformationComplete")); alert(chrome.i18n.getMessage("copyDebugInformationComplete"));
}) })
.catch(() => { .catch(() => {
alert(chrome.i18n.getMessage("copyDebugInformationFailed")); alert(chrome.i18n.getMessage("copyDebugInformationFailed"));
}); });
} }
function isIncognitoAllowed(): Promise<boolean> { function isIncognitoAllowed(): Promise<boolean> {

View file

@ -1,4 +1,4 @@
import Config from "./config"; import Config, { generateDebugDetails } from "./config";
import Utils from "./utils"; import Utils from "./utils";
import { import {
@ -12,6 +12,7 @@ import {
GetChannelIDResponse, GetChannelIDResponse,
IsChannelWhitelistedResponse, IsChannelWhitelistedResponse,
IsInfoFoundMessageResponse, IsInfoFoundMessageResponse,
LogResponse,
Message, Message,
MessageResponse, MessageResponse,
PopupMessage, PopupMessage,
@ -184,7 +185,8 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
"exportSegmentsButton", "exportSegmentsButton",
"importSegmentsMenu", "importSegmentsMenu",
"importSegmentsText", "importSegmentsText",
"importSegmentsSubmit" "importSegmentsSubmit",
"debugLogs"
].forEach(id => PageElements[id] = document.getElementById(id)); ].forEach(id => PageElements[id] = document.getElementById(id));
@ -255,6 +257,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
PageElements.helpButton.addEventListener("click", openHelp); PageElements.helpButton.addEventListener("click", openHelp);
PageElements.refreshSegmentsButton.addEventListener("click", refreshSegments); PageElements.refreshSegmentsButton.addEventListener("click", refreshSegments);
PageElements.sbPopupIconCopyUserID.addEventListener("click", async () => copyToClipboard(await getHash(Config.config.userID))); PageElements.sbPopupIconCopyUserID.addEventListener("click", async () => copyToClipboard(await getHash(Config.config.userID)));
PageElements.debugLogs.addEventListener("click", copyDebgLogs);
// Forward click events // Forward click events
if (window !== window.top) { if (window !== window.top) {
@ -1143,6 +1146,12 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
} }
} }
function copyDebgLogs() {
sendTabMessage({ message: "getLogs" }, (logs: LogResponse) => {
copyToClipboard(`${generateDebugDetails()}\n\nWarn:\n${logs.warn.join("\n")}\n\nDebug:\n${logs.debug.join("\n")}`);
});
}
function onMessage(msg: PopupMessage) { function onMessage(msg: PopupMessage) {
switch (msg.message) { switch (msg.message) {
case "time": case "time":