Explain Codes LogoExplain Codes Logo

Chrome Dev Tools - Modify javascript and reload

javascript
chrome-dev-tools
local-overrides
javascript-modification
Alex KataevbyAlex Kataev·Dec 8, 2024
TLDR

Need a quick win? Just trigger Chrome's Local Overrides. Right in Chrome Dev Tools > Sources, right-click on the desired JavaScript file, select Save for overrides, tweak the code, hit Ctrl+S (Cmd+S on Mac). Upon page refresh, your edits will stick around.✨

Example:

  1. Fire up Chrome Dev Tools, switch to Sources.
  2. Right-click on the required file, Save for overrides.
  3. Edit the code, signal with Ctrl+S (Cmd+S).
  4. Refresh to observe your persistent changes.

Deep dive: unlocking local overrides potential

Beneath Chrome Dev Tools architecture lies a feature gem — Local Overrides! This time-saver enables you to see realtime changes without refiring a new development build. Configuring a local directory for overrides, the changes persist on your disk, supporting your hotfix experiments across sessions.

Setting up local overrides: a step-by-step guide

Here's the insider's guide to enabling this powerful feature:

  1. First, open DevTools, then access Settings (the gear icon at the top-right corner) or simply F1.
  2. Make that Local Overrides option under Experiments ticked.
  3. Find your way to Sources, then navigate to the Filesystem tab within the panel. Now set up your local directory by clicking +.
  4. Permit Chrome to enjoy its read/write access to the directory you defined.
  5. Choose your file, right-click, and click on Save for overrides to create a local copy for edits.

Extensions and tools for better control

Longing for specialized control or needing a fit in an already established workflow? Resource Override extension or Fiddler's AutoResponder might be the exact kit. Each offers ways to maintain edits even after reloading.

Resource Override steps:

  1. Install the extension from the Chrome Web Store. (Could they make it any easier?)
  2. Set file rules for specific files to redirect to local files on your disk. (Because who wouldn't want control?)
  3. Changes made to local files stay even after page refresh. (Persistence pays, right?)

Fiddler AutoResponder steps:

  1. Run Fiddler and ensure a proper configuration for HTTPS traffic.
  2. Open the AutoResponder tab in Fiddler.
  3. Create a rule in AutoResponder to divert the traffic for a selected JavaScript file to your local edited version.

Troubleshooting and key problem areas

Unforeseen confrontations in the real world of modifying JavaScript:

  • Not persisting override: Confirm overrides directory permissions are set right and Chrome points to the exact directory.
  • Lost breakpoints: Don't forget to verify breakpoints after changes.
  • Decreased performance: Keep a balance. Excessive use of overrides can affect debugging speed. Regular health checks are good for your process.

Best practices for local modification

  • Backup is your best friend: Always shield your original files — save backup before venturing into changes.
  • Embrace version control: Keep your code changes under surveillance with Git or another version control system.
  • Test like there's no tomorrow: Test your changes. Local Overrides is not a replacement for a proper development or staging environment.