ditoslav
ditoslav

Reputation: 4892

Is it possible to change script running clientside on a webpage?

So I'm playing a game online on my laptop and it is a pretty simple html5 game but the optimization is nonexistant. The game with a few circles on my screen is using 85% of my cpu.

Logically, I started profiling the game and was trying to figure out if I could optimize it for my laptop. Now, what I'm wondering is how could I run the game but with a tweaked version of the JS script that is running.

If I try to save the page and run it from my laptop it of course has CORS issues so I can not access the server.

Can I somehow change the script a bit which is executing in my browser but while still staying "inside the webpage" which is running so that I may normally make XHR requests to the server?

Also, although this is not in the title of the question, can I somehow proxy the XHR request to my script but while not breaking the CORS rule?

Why is it so different if I run the same thing from my browser and from a saved HTML on my desktop? I have the same IP and am doing the same thing but from the url it "feels like" I'm running it from somewhere else. Can I somehow imitate that I'm running "from the webpage" but instead run it from a modified saved html?

Upvotes: 7

Views: 5327

Answers (1)

JSelser
JSelser

Reputation: 3630

You could proxy, given there isn't a cross domain protection mechanism or some sort of logging in (which complicates stuff).

What you could very well do is use a browser extension which allows you to add CSS, HTML and JavaScript.

I'm not entirely savvy on extensions so I'm not sure you can modify existing code but I'm guessing that if you can add arbitrary JS code you may very well replace the script tag containing the game for a similar personally modified script based on it. It's worth a try...

Link to getting started with chrome extensions

Update:

If you're set on doing it, proxying ammounts to requesting an URL with your application and do something with the page (html) instead of the original source. I assume you want to change the page and serve it to your browser.

With this in mind you will need the following, I dont know C# so you'll have to google around for libraries and utilities:

  • a way to request URLs (see link at bottom)
  • a way to modify the page, you need a DOM crawler
  • a way to start said process and serve it to your browser by hitting your own URL, meaning you need some sort of web server

I found the following question specifically on proxying with C#

Upvotes: 3

Related Questions