DinoDevs / GladiatusCrazyAddon

This was "A browser addon for the Gladiatus browser game."
https://gladiatus.dinodevs.com
GNU General Public License v3.0
41 stars 31 forks source link

Store errors feature #476

Closed FrutyX closed 1 week ago

FrutyX commented 3 months ago

This time I won't hesisate to ask for your help, because this is something I wanted to have a long time ago, but never finished it, and instead of scrapping it completely, for you it should be child's play, not to mention you do your own tweaks anyways.

The basics are set, from my own testing, it's working as expected. All I am asking from you is the implementation into global.js, I have encountered a few issues and errors during the implementation and it... let's just say it got too messy.

The code ``` // Catch and store errors (function() { const originalConsoleError = console.error; console.error = function(...args) { // Call originalConsoleError.apply(console, args); // Current errors const errors = JSON.parse(localStorage.getItem('gcaErrors') || '[]'); // Add errors.push(args); // Save errors localStorage.setItem('gcaErrors', JSON.stringify(errors)); // Show the error button if it's not already displayed showErrorButton(); }; })(); ``` ``` // Show button if errors exists function showErrorButton() { const errors = JSON.parse(localStorage.getItem('gcaErrors') || '[]'); if (errors.length > 0) { // Create button if (!document.getElementById('errorButton')) { const errorButton = document.createElement('button'); errorButton.className = 'awesome-button'; errorButton.innerText = gca_locale.get("general", "error"); errorButton.style.position = 'relative'; errorButton.style.top = '-1px'; errorButton.style.left = '5px'; errorButton.style.zIndex = '1'; errorButton.id = 'errorButton'; const footerButton = document.getElementById('gca-footer-links'); if (footerButton) { footerButton.appendChild(errorButton); } // Click event errorButton.addEventListener('click', function() { showErrorsModal(); }); } } } ``` ``` //Create modal for logs function showErrorsModal() { const errors = JSON.parse(localStorage.getItem('gcaErrors') || '[]'); const errorText = errors.map(e => e.join(' ')).join(' '); var modal = new gca_tools.Modal( gca_locale.get("general", "error"), null, () => { modal.destroy(); } ); modal.body(errorText); modal.button(gca_locale.get("general", "ok"), true); modal.show(); } ```

Description

I was inspired by another browser extension (also for a browser game) that has this. The script is supposed to store console errors and if errors are detected, it will create a button, this button is in the footers links, I have chosen this position so it's not in the way.

This button, when clicked, brings out a modal with logged errors, so you can also copy&paste them.

This feature is not for us, but for casual players, some will tell you "I have a problem" and that's pretty much it, if the console returns an error, you can point those players at this specific button, I believe in some cases this could help.

Notes:

I thank you.

FrutyX commented 3 months ago

Something I forgot to add and mention, we need to store only errors from GCA, in case Gladiatus will make some. An identifier...

FrutyX commented 3 months ago

And since I know Thanos will not like this, we could possibly move the button to settings, under the Data section, however, to log the errors, the script must run in the background all the time anyways.

But I leave those things to you.

FrutyX commented 3 months ago

Ah, yes Thanos, I see your point.

No more adding new features, which I also wanted, in this case, I thought this might prove useful tho, especially for us.

Only keeping GCA on life support was and is the main goal. I'll close this for now, I mean, you can always find it here, if you want.

GramThanos commented 3 months ago

Well I didn't say anything. I know how to implement this, but this is a bad period for me, so you have to give me more time.

GramThanos commented 3 months ago

image image

GramThanos commented 3 months ago

FYI, this may not be able to catch all the errors, as some of the errors may be fired before the handler starts to listen for errors.

FrutyX commented 3 months ago

Oh! This is even better than I imaged it! Very nice, I only wish we had this sooner.

I do hope that this will prove useful, in the future, actually, let's hope we won't need that, heh.

Thank you.

FrutyX commented 3 months ago

If you want, we can improve the message by adding the OS and Browser (+version) in it. Less asking, more copy-pasting.

If it won't cause any issues, that is.

FrutyX commented 3 months ago

Maybe even user's language, because that can sometimes cause issues too.

Just my ideas, we want only the useful info.

FrutyX commented 3 months ago

Thanos, I may need your skill and expertise, you see, I really like this feature, I really do. However, I was hunting down errors, oh and boy, I found some.

You can produce countless errors during traveling between countries (or to the underworld), since pages are blocked by the travel and elements required does not exist.

First, I thought about editing every function that does this, I already did something like that in https://github.com/DinoDevs/GladiatusCrazyAddon/commit/e1838d69e73b56881ac41962cdc69a374c9ce52e (tho that was mostly because of a conflicting feature, and this fixed it), but this solution is far from being ideal, editing so many features isn't best and can create other issues, it's just, meh.

Second, I thought that maybe we could do a check if the player is traveling and disable this feature completely.

Third, give players the option to disable this feature (but 100% leave it on by default), if they dont want it OR ignore (specific?) errors (by the player).

Best approach? I don't know, and I don't want to dig alone in it honestly, so I leave this in your capable hands, thanks.

GramThanos commented 3 months ago

In general, error handling should be a bit independent as a system, thus, mixing it with settings is a bad idea.

There are pages where scripts should not run, and thus putting a check before executing something is the way to do it.

GramThanos commented 3 months ago

I am a bit overloaded these days, I can look into it next week.

FrutyX commented 3 months ago

I am a bit overloaded these days, I can look into it next week.

Sure, no rush, I don't think GCA is going anywhere, when you have the time, feel free to take a look at it. Rather you than me. There are some things I don't want to touch.

FrutyX commented 3 months ago

In hopes this may save you some time next week, I have created a collection of all the errors I found. A player can access any of these during traveling between countries (or exiting the Underworld), since those pages are restricted:

mod=reports

reports.js?4.3.8&built=1719610536711:237 Uncaught TypeError: Cannot read properties of undefined (reading 'textContent')
    at Object.change (reports.js?4.3.8&built=1719610536711:237:64)
    at Object.inject (reports.js?4.3.8&built=1719610536711:72:24)
    at fireLoad (reports.js?4.3.8&built=1719610536711:1194:15)

mod=arena&submod=serverArena&aType=2 and mod=arena&submod=serverArena&aType=3

arena.js?4.3.8&built=1719610656898:96 Uncaught TypeError: Cannot read properties of null (reading 'classList')
    at Object.overhaul_tables (arena.js?4.3.8&built=1719610656898:96:39)
    at Object.preinject (arena.js?4.3.8&built=1719610656898:13:9)
    at arena.js?4.3.8&built=1719610656898:1090:12
    at arena.js?4.3.8&built=1719610656898:1097:3

mod=guildLibrary

guild.library.js?4.3.8&built=1719610765086:41 Uncaught TypeError: Cannot read properties of undefined (reading 'textContent')
    at Object.improve (guild.library.js?4.3.8&built=1719610765086:41:80)
    at Object.inject (guild.library.js?4.3.8&built=1719610765086:13:17)
    at fireLoad (guild.library.js?4.3.8&built=1719610765086:172:21)

mod=guildMarket

markets.js?4.3.8&built=1719610795374:397 Uncaught TypeError: Cannot read properties of null (reading 'parentNode')
    at Object.oneGoldMode (markets.js?4.3.8&built=1719610795374:397:10)
    at Object.inject (markets.js?4.3.8&built=1719610795374:59:9)
    at fireLoad (markets.js?4.3.8&built=1719610795374:748:15)
    oneGoldMode @ markets.js?4.3.8&built=1719610795374:397
    inject @ markets.js?4.3.8&built=1719610795374:59
    fireLoad @ markets.js?4.3.8&built=1719610795374:748
markets.js?4.3.8&built=1719610795374:104 Uncaught TypeError: Cannot read properties of null (reading 
    'getElementsByTagName')
    at HTMLDocument.<anonymous> (markets.js?4.3.8&built=1719610795374:104:46)
    at j (376b06b9c8a4781859a0be73186167.js:3:27547)
    at Object.fireWith [as resolveWith] (376b06b9c8a4781859a0be73186167.js:3:28366)
    at Function.ready (376b06b9c8a4781859a0be73186167.js:3:30205)
    at HTMLDocument.J (376b06b9c8a4781859a0be73186167.js:3:30571) 

mod=guildStorage

guild.storage.js?4.3.8&built=1719610850261:49 Uncaught TypeError: Cannot read properties of null (reading 
    'getElementsByClassName')
    at Object.dollItems (guild.storage.js?4.3.8&built=1719610850261:49:47)
    at Object.inject (guild.storage.js?4.3.8&built=1719610850261:43:9)
    at Object.inject (guild.storage.js?4.3.8&built=1719610850261:18:21)
    at fireLoad (guild.storage.js?4.3.8&built=1719610850261:292:21)

mod=guildBankingHouse

guild.bank.js?4.3.8&built=1719610934515:52 Uncaught TypeError: Cannot read properties of undefined (reading 
    'getElementsByTagName')
    at Object.improve (guild.bank.js?4.3.8&built=1719610934515:52:37)
    at Object.inject_donatePage (guild.bank.js?4.3.8&built=1719610934515:28:22)
    at Object.inject (guild.bank.js?4.3.8&built=1719610934515:14:9)
    at fireLoad (guild.bank.js?4.3.8&built=1719610934515:321:18)  

mod=guild_jail

guild.jail.js?4.3.8&built=1719610969353:68 Uncaught TypeError: Cannot read properties of undefined (reading 
    'getElementsByTagName')
    at Object.improve (guild.jail.js?4.3.8&built=1719610969353:68:115)
    at Object.inject (guild.jail.js?4.3.8&built=1719610969353:13:17)
    at fireLoad (guild.jail.js?4.3.8&built=1719610969353:252:18) 

mod=player&p= and mod=settings&submod=charSettings

Uncaught TypeError: Cannot read properties of null (reading 'getElementsByClassName')
    at Object.dollItems (player.js?4.3.8&built=1719611023565:77:47)
    at Object.inject (player.js?4.3.8&built=1719611023565:71:9)
    at Object.inject (player.js?4.3.8&built=1719611023565:15:20)
    at fireLoad (player.js?4.3.8&built=1719611023565:544:14)

mod=underworld&submod=exit

global.js?4.3.8&built=1719646149416:578 Uncaught TypeError: Cannot read properties of undefined (reading '0')
    at Object.showTimer (global.js?4.3.8&built=1719646149416:578:40)
    at Object.init (global.js?4.3.8&built=1719646149416:548:10)
    at Object.inject (global.js?4.3.8&built=1719646149416:148:35)
    at fireLoad (global.js?4.3.8&built=1719646149416:6117:14)

For the last one, the Underworld one, I know adding this to it works, but I already said I will let you handle it, because we have multiple errors like these:

if (!Array.isArray(tooltip) || !tooltip[0] || !tooltip[0][1] || !tooltip[0][1][0]) return;