Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 831
ditoslav Avatar asked Jul 06 '15 10:07

ditoslav


People also ask

Can you edit client-side JavaScript?

You can't modify the js file on client side. However, if you just want to add some code, you can use userscript.

How do I change the script on my website?

Click on “Developer Tools.” This should open an inspector panel at the bottom of your browser window to view the web page's source code and make numerous tweaks, including editing the text. Click on the cursor icon in the top left corner of the inspector panel. Use the cursor to highlight the text you'd like to modify.

What kind of script is used to run code on the client?

Client-side scripting simply means running scripts, such as JavaScript, on the client device, usually within a browser. All kinds of scripts can run on the client side if they are written in JavaScript, because JavaScript is universally supported.

How does client-side scripting work?

A client-side script is a program that is processed within the client browser. These kinds of scripts are small programs which are downloaded , compiled and run by the browser. JavaScript is an important client-side scripting language and widely used in dynamic websites.


1 Answers

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#

like image 150
JSelser Avatar answered Oct 05 '22 02:10

JSelser