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://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>
<br />
<a id="debugLogs">__MSG_copyDebugLogs__</a>
</footer>
<button id="showNoticeAgain" style="display: none">__MSG_showNotice__</button>

View file

@ -477,4 +477,26 @@ const localDefaults = {
};
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
}));
break;
case "getLogs":
sendResponse({
debug: window["SBLogs"].debug,
warn: window["SBLogs"].warn
});
break;
}
sendResponse({});

View file

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

View file

@ -1,7 +1,7 @@
import * as React from "react";
import { createRoot } from 'react-dom/client';
import Config from "./config";
import Config, { generateDebugDetails } from "./config";
import * as CompileConfig from "../config.json";
import * as invidiousList from "../ci/invidiouslist.json";
@ -698,32 +698,14 @@ function validateServerAddress(input: string): string {
}
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
navigator.clipboard.writeText(JSON.stringify(output, null, 4))
.then(() => {
navigator.clipboard.writeText(generateDebugDetails())
.then(() => {
alert(chrome.i18n.getMessage("copyDebugInformationComplete"));
})
.catch(() => {
})
.catch(() => {
alert(chrome.i18n.getMessage("copyDebugInformationFailed"));
});
});
}
function isIncognitoAllowed(): Promise<boolean> {

View file

@ -1,4 +1,4 @@
import Config from "./config";
import Config, { generateDebugDetails } from "./config";
import Utils from "./utils";
import {
@ -12,6 +12,7 @@ import {
GetChannelIDResponse,
IsChannelWhitelistedResponse,
IsInfoFoundMessageResponse,
LogResponse,
Message,
MessageResponse,
PopupMessage,
@ -184,7 +185,8 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
"exportSegmentsButton",
"importSegmentsMenu",
"importSegmentsText",
"importSegmentsSubmit"
"importSegmentsSubmit",
"debugLogs"
].forEach(id => PageElements[id] = document.getElementById(id));
@ -255,6 +257,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
PageElements.helpButton.addEventListener("click", openHelp);
PageElements.refreshSegmentsButton.addEventListener("click", refreshSegments);
PageElements.sbPopupIconCopyUserID.addEventListener("click", async () => copyToClipboard(await getHash(Config.config.userID)));
PageElements.debugLogs.addEventListener("click", copyDebgLogs);
// Forward click events
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) {
switch (msg.message) {
case "time":