20

I'm looking for a browser extension (Firefox, Chrome) allowing to replace a Javascript file on a live Web site to do some testing/hacking.

Basically, it should take a URL and load another one instead (locally or on a HTTP development server).

Any idea?

Grégoire Cachet
  • 2,547
  • 3
  • 29
  • 27
  • 1
    Looks like http://stackoverflow.com/questions/7782069/replace-some-remote-javascript-file-with-a-local-debugging-copy-using-greasemonk – Maël Nison Aug 10 '12 at 10:20

11 Answers11

5

Try http://www.fiddler2.com/fiddler2/version.asp

It does that and much more. But it's not a browser extension.

Josh E
  • 7,390
  • 2
  • 32
  • 44
ColBeseder
  • 3,579
  • 3
  • 28
  • 45
  • 1
    404 webpage, cant modify ssl-html, unable to redirect without https – Grim Aug 09 '12 at 08:22
  • 1
    @ColBeseder - I've edited your answer to point to the correct URL. Fiddler is exactly the thing the OP is looking for – Josh E Aug 09 '12 at 23:17
  • 1
    @PeterRader normally fiddler allows you to inject in ssl connections, but obviously the certificate won't validate anymore. https://www.fiddler2.com/Fiddler/help/httpsdecryption.asp –  Aug 10 '12 at 15:25
  • The question was to replace a javascript file in the browser and not somewhere else. – Brain Oct 24 '18 at 09:06
1

The Opera browser has similar functionality:

  1. View source code of the page (Ctrl+U).
  2. Make some changes. Or paste and replace the entire file.
  3. Press Apply Changes in the toolbar (Ctrl+R).

For editing linked resources (such as javascript or CSS files), use the following approach:

  1. Open the linked resource in a new tab.
  2. View "source code" of the resource (Ctrl+U).
  3. Make some changes.
  4. Press Apply Changes in the toolbar (Ctrl+R).
  5. Return to the tab with the webpage and realod (Ctrl+R).
Tereza Tomcova
  • 4,928
  • 4
  • 30
  • 29
  • Indeed, this method won't work with the new Opera. There's a built-in web inspector that can be used for live editing of HTML and CSS. Not JS unfortunately. I suppose it should be possible to replace existing JS functions using the console. – Tereza Tomcova Jan 31 '14 at 03:41
  • 1
    It is worth to mention that Chrome also support this via Developer Tools. – Destiner Apr 09 '16 at 20:26
1

Alternatives:

  • Using chrome you can change code on the fly (Developer tools -> Sources tab) and just save it (command + s)
  • Use the LiveReload app that actually attaches an extension (that kind of does what you want) http://livereload.com/

This may not be the "exact" answer to your question, yet I almost sure one of those will do what you want to do.

phaistonian
  • 94
  • 1
  • 4
1

I think this is a task for a personal proxy. You can sniff traffic on the proxy and apply rules to modify requests/content

DmitryK
  • 5,542
  • 1
  • 22
  • 32
1

Not sure if this helps or not, but I just encountered a chrome plugin called Resource Override, which sounds like it does something similar. Im trying out the Fiddler which someone else mentioned, but I think i'm also going to try this one at some point. https://chrome.google.com/webstore/detail/resource-override/pkoacgokdfckfpndoffpifphamojphii?hl=en

Josh Brown
  • 925
  • 11
  • 13
  • Resource Override is probably the easiest solution on Linux. As probably is fiddler on Windows. – x-yuri Apr 19 '20 at 02:12
0

You can intercept and block requests in browsers. For example in Chrome you can use the beforeload event check if it's a JS (event.target is script tag or event.url ends in .js) call event.preventDefault() and then load your own script instead.

I'm pretty sure there's a similar way to do this in FF.

gblazex
  • 49,155
  • 12
  • 98
  • 91
0

There is https everywhere which lets you define rules for url rewrites. This should work on all request, including script requests.

Tamper data might do the job, but I don't know how automated/permanent you can set it up.

And there is also an extension called redirector. I didn't test that one. Potentially it only works on the address bar.

Update:

That is unfortunate. In that case probably a proxy is you only way. What about a firefox extension that is a proxy, like Foxyproxy

0

ColBeseder correctly brings up Fiddler (http://www.fiddler2.com/fiddler2/version.asp) as a solution to your issue.

Fiddler is perfectly capable of handling and decrypting HTTPS traffic as well - see the documentation on the page for how to configure it.

To directly answer the OP question, you can use the autoresponder feature in Fiddler to hack your production JS for testing.

Enable the autoresponder tab in Fiddler, making sure to leave pass through for unmatched requests checked, entering the URL of the JS files you want to substitute as the pattern. Select the response file from your local filesystem, and go to town!

See http://yuiblog.com/blog/2008/06/27/fiddler/ (bottom of article is most relevant) for an example.

Josh E
  • 7,390
  • 2
  • 32
  • 44
0

You should probably consider robohydra, since it is specifically developed for your case. They do not support https yet, but they are open to including it in the future.

Nacho Coloma
  • 7,070
  • 2
  • 40
  • 43
0

Disclaimer: I'm the author of the software :-)

A different approach that might suit your usecase better is to use a RoboHydra-based development proxy. The idea here would be that you want to keep ALL Javascript files in your machine, and use another server simply as a backend. It's great for eg. front-end developers that don't want to have the whole backend installed in their machines.

You can see the documentation, tutorials and such at http://robohydra.org/, and have an article describing exactly that usecase at http://dev.opera.com/articles/view/robohydra-a-new-testing-tool-for-client-server-interactions/.

However, as of now it can't proxy to HTTPS URLs, but that should be a trivial change that I intend to do soon anyway.

-1

How about Greasemonkey? That should be the thing you're searching for!

Marvin Emil Brach
  • 3,984
  • 1
  • 32
  • 62
  • Greasemonkey cant replace the Behave. – Grim Aug 03 '12 at 14:11
  • when you replace the functions it's possible, have a look: http://www.squakmt.com/replacing_javascript/index.htm . But you're right, the answer isn't correct enough. – Marvin Emil Brach Aug 03 '12 at 14:34
  • i cant replace functions in – Grim Aug 03 '12 at 15:05
  • yeah I see... How's with [Opera User Scripts](http://de.opera.com/docs/userjs/using/#whatcando)? Get's executed before any scripts: `User JavaScript is loaded and executed as if it were a part of the page that you visit. It is run immediately before the first script on the page`, and you can prevent scripts from being executed: `Controlling what scripts are allowed to run on a page, and what they are allowed to do` – Marvin Emil Brach Aug 03 '12 at 15:20
  • @MarvinEmilBrach: I would have answered with that (I currently have such a setup running), but the OP asked for a extension for FF/Chrome - and probably wants a GUI. – Bergi Aug 03 '12 at 15:54