Remote Debugging with Charles Proxy

By  on  
Charles Proxy

The most difficult part of supporting TV apps when you didn't create them and don't have access to the source code is debugging them when asked for help.  It's almost an unfair request -- "we wont give you access to edit the code but we want you to give use the answer."  Editing remote code is a pain...but thanks to Charles this practice got a whole lot easier.  Charles allows me to intercept calls to remote CSS and JavaScript files and substitute my own, allowing for infinitely easier debugging of remote code I don't have access to change.

Charles is loaded with features, so much so that it becomes confusing.  I'm hoping to make that more simple for you; in this post I will walk you through file replacement for the purpose of remote debugging of web apps.

Charles is a paid app which provides a 30 day trial.  I've not been paid or even asked to endorse Charles; it's the tool I use for remote debugging so I've chosen to write about it.

Charles can do just about everything but we're going to limit this post to solving one frequent problem:  swapping out a remote file for a local file that we can substitute, thus allowing us complete control over its contents and allowing us to an opportunity to fix any problems!

Remote Debugging

To swap out a remote file for a local file, the first step is using the Charles menu and choosing Tools>Map Remote.  The Map Remote Settings window pops up with a listing of remotes you've defined; to add one, click the "Add" button and you'll see the following screen:

Charles Proxy

The top block is for remote file settings and the second block is for your local substitution settings.  This means your file must be "served" (not using the file:// protocol); you can use Python or Node.js to easily serve a directory.  Assuming you're serving the file, you'll enter the remote URL settings first, followed by your local settings.  Here's an example:

Charles Proxy

The screenshot above shows me replacing a production MDN .js file with a local file.  To ensure the local file is being used, place a special console.log call at the top of the file and ensure the message is within the console.

This is just one of the simpler features that Charles provides but it has made my life much, much easier.  Debugging remote applications went from impossible to effortless after inputting a few rules into Charles.  If you have a good method for accomplishing this without Charles, I'd love to know, please share!

Recent Features

  • By
    Create Namespaced Classes with MooTools

    MooTools has always gotten a bit of grief for not inherently using and standardizing namespaced-based JavaScript classes like the Dojo Toolkit does.  Many developers create their classes as globals which is generally frowned up.  I mostly disagree with that stance, but each to their own.  In any event...

  • By
    7 Essential JavaScript Functions

    I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener and attachEvent.  Times have changed but there are still a few functions each developer should...

Incredible Demos

  • By
    HTML5 Context Menus

    One of the hidden gems within the HTML5 spec is context menus. The HTML5 context menu spec allows developers to create custom context menus for given blocks within simple menu and menuitem elements. The menu information lives right within the page so...

  • By
    Create Custom Events in MooTools 1.2

    Javascript has a number of native events like "mouseover," "mouseout", "click", and so on. What if you want to create your own events though? Creating events using MooTools is as easy as it gets. The MooTools JavaScript What's great about creating custom events in MooTools is...

Discussion

  1. So far I had been editing the source codes by logging in through the FTP, taking back ups and editing and uploading the edited version. It would be interesting to try Charles to find out if it could help cut out some steps.

  2. Trevor W

    Thanks so much for the help! Especially the links to python HTTP hosting. I do have a question though – I ran everything like you said but no .js file is swapped :(
    When I go to my file at http://0.0.0.0:8000/local.js in the browser, it also shows a Charles Proxy error that it can’t connect to remote host. Actual error:
    java.net.ConnectException: Connection refused (Connection refused)
    What is wrong? Is there some proxy setting buried somewhere that I need to change in order to access locally hosted files?

  3. You can also try the Requestly Redirect URL feature (https://requestly.io/feature/redirect-url/) to redirect your remote JS/CSS code to your local files.

    Requestly is available as a browser extension so it doesn’t impact your network settings by applying proxy to all applications. It’s pretty simple to use and comes with a free plan.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!