Added copy debug information to clipboard options element.

This commit is contained in:
Joe Dowd
2020-03-18 00:15:04 +00:00
parent 457bd15e17
commit e73d79071c
3 changed files with 67 additions and 0 deletions

View File

@@ -440,5 +440,17 @@
},
"incorrectlyFormattedOptions": {
"message": "This JSON is not formatted correctly. Your options have not been changed."
},
"copyDebugInformation": {
"message": "Copy Debug Information To Clipboard"
},
"copyDebugInformationFailed": {
"message": "Failed to write to clipboard"
},
"copyDebugInformationOptions": {
"message": "Copies information to the clipboard to be provided to a developer when raising a bug / when a developer requests it. Sensitive information such as your user ID, whitelisted channels, and custom server address have been removed. However it does contain information such as your useragent, browser, operating system, and extension version number. "
},
"copyDebugInformationComplete": {
"message": "The debug information has been copied to the clip board. Feel free to remove any information you would rather not share. Save this in a text file or paste into the bug report."
}
}

View File

@@ -334,6 +334,20 @@
<br/>
<br/>
<div option-type="button-press" sync-option="copyDebugInformation" confirm-message="copyDebugInformation">
<div class="option-button trigger-button">
__MSG_copyDebugInformation__
</div>
<br/>
<div class="small-description">__MSG_copyDebugInformationOptions__</div>
</div>
<br/>
<br/>
<div option-type="text-change" sync-option="serverAddress">
<label class="text-label-container">
<div>__MSG_customServerAddress__</div>

View File

@@ -1,4 +1,6 @@
import Config from "./config";
import * as CompileConfig from "../config.json";
// Make the config public for debugging purposes
(<any> window).SB = Config;
@@ -126,6 +128,16 @@ async function init() {
invidiousInstanceAddInit(<HTMLElement> optionsElements[i], privateTextChangeOption);
}
break;
case "button-press":
let actionButton = optionsElements[i].querySelector(".trigger-button");
switch(optionsElements[i].getAttribute("sync-option")) {
case "copyDebugInformation":
actionButton.addEventListener("click", copyDebugOutputToClipboard);
break;
}
break;
case "keybind-change":
let keybindButton = optionsElements[i].querySelector(".trigger-button");
@@ -433,3 +445,32 @@ function validateServerAddress(input: string): string {
return input;
}
function copyDebugOutputToClipboard() {
// Build output debug information object
let output = {
debug: {
userAgent: navigator.userAgent,
platform: navigator.platform,
language: navigator.language,
extensionVersion: chrome.runtime.getManifest().version
},
config: JSON.parse(JSON.stringify(Config.localConfig)) // 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(() => {
alert(chrome.i18n.getMessage("copyDebugInformationComplete"));
})
.catch(err => {
alert(chrome.i18n.getMessage("copyDebugInformationFailed"));
});;
}