web: Prevent "414 URI Too Long" error on Github when reporting bugs

This commit is contained in:
Toad06 2021-01-07 14:58:40 +01:00 committed by Mike Welsh
parent 44e9185a5f
commit b81fb64be9
1 changed files with 46 additions and 25 deletions

View File

@ -728,42 +728,63 @@ export class RufflePlayer extends HTMLElement {
} }
this.panicked = true; this.panicked = true;
let errorText = "# Error Info\n"; const errorArray: Array<string | null> & {
stackIndex: number;
} = Object.assign([], {
stackIndex: -1,
});
errorArray.push("# Error Info\n");
if (error instanceof Error) { if (error instanceof Error) {
errorText += `Error name: ${error.name}\n`; errorArray.push(`Error name: ${error.name}\n`);
errorText += `Error message: ${error.message}\n`; errorArray.push(`Error message: ${error.message}\n`);
if (error.stack) { if (error.stack) {
errorText += `Error stack:\n\`\`\`\n${error.stack}\n\`\`\`\n`; const stackIndex =
errorArray.push(
`Error stack:\n\`\`\`\n${error.stack}\n\`\`\`\n`
) - 1;
errorArray.stackIndex = stackIndex;
} }
} else { } else {
errorText += `Error: ${error}\n`; errorArray.push(`Error: ${error}\n`);
} }
errorText += "\n# Player Info\n"; errorArray.push("\n# Player Info\n");
errorText += this.debugPlayerInfo(); errorArray.push(this.debugPlayerInfo());
errorText += "\n# Page Info\n"; errorArray.push("\n# Page Info\n");
errorText += `Page URL: ${document.location.href}\n`; errorArray.push(`Page URL: ${document.location.href}\n`);
if (this.swfUrl) errorText += `SWF URL: ${this.swfUrl}\n`; if (this.swfUrl) errorArray.push(`SWF URL: ${this.swfUrl}\n`);
errorText += "\n# Browser Info\n"; errorArray.push("\n# Browser Info\n");
errorText += `Useragent: ${window.navigator.userAgent}\n`; errorArray.push(`Useragent: ${window.navigator.userAgent}\n`);
errorText += `OS: ${window.navigator.platform}\n`; errorArray.push(`OS: ${window.navigator.platform}\n`);
errorText += "\n# Ruffle Info\n"; errorArray.push("\n# Ruffle Info\n");
errorText += `Version: %VERSION_NUMBER%\n`; errorArray.push(`Version: %VERSION_NUMBER%\n`);
errorText += `Name: %VERSION_NAME%\n`; errorArray.push(`Name: %VERSION_NAME%\n`);
errorText += `Channel: %VERSION_CHANNEL%\n`; errorArray.push(`Channel: %VERSION_CHANNEL%\n`);
errorText += `Built: %BUILD_DATE%\n`; errorArray.push(`Built: %BUILD_DATE%\n`);
errorText += `Commit: %COMMIT_HASH%\n`; errorArray.push(`Commit: %COMMIT_HASH%\n`);
const issueTitle = `Ruffle Error on ${document.location.href}`; const errorText = errorArray.join("");
const issueLink =
"https://github.com/ruffle-rs/ruffle/issues/new?title=" + const issueTitle = `Error on ${document.location.href}`;
encodeURIComponent(issueTitle) + let issueLink = `https://github.com/ruffle-rs/ruffle/issues/new?title=${encodeURIComponent(
"&body=" + issueTitle
encodeURIComponent(errorText); )}&body=`;
let issueParameters = encodeURIComponent(errorText);
if (
errorArray.stackIndex > -1 &&
String(issueLink + issueParameters).length > 8195
) {
// Strip the stack error from the array when the produced URL is way too long.
// This should prevent "414 Request-URI Too Large" errors on Github.
errorArray[errorArray.stackIndex] = null;
issueParameters = encodeURIComponent(errorArray.join(""));
}
issueLink += issueParameters;
// Clears out any existing content (ie play button or canvas) and replaces it with the error screen // Clears out any existing content (ie play button or canvas) and replaces it with the error screen
this.container.innerHTML = ` this.container.innerHTML = `