Can Firefox's "view source" be set to not make a new GET request?
Asked Answered
I

12

51

This is sort of tangential to coding, but programmers often do "view source" on their own pages and on others' pages. I learned that when you do the normal View Source in Firefox, it takes the URL you're at and issues another GET request to that URL. There are two reasons why this is bad:

  1. If you've just issued a POST and do View Source, you won't see the HTML that your browser is actually rendering for you.
  2. If the site author has incorrectly made a form that takes some action (sends email or writes to a DB or whatever), then that action will be taken (or attempted, anyway) again. That's sort of dangerous.

I'd heard there was something I could add to about:config that would prevent this, but had no luck. I also read about some extensions that would get around this, Firebug chief among them, but ctrl-shift-u is so convenient when compared to F12 and then a couple of clicks to find the element you're interested in.

So... Is there a switch I can flip to make Firefox's View Source act like View Generated Source all the time and hit the cache instead of making a new GET request?

Inhesion answered 4/3, 2009 at 17:26 Comment(9)
Well, keyboard shortcuts aside, Firebug adds an "Inspect Element" option to the page's context menu. That makes finding the element you are interested in much easier than using view source, IMHO.Nabonidus
I guess I feel that the keyboard shortcut is pretty important. I don't want to have to hit my mouse if I can help it sometimes and doing inspect in Firebug or right-clicking for view selection source or selecting View Generated Source all require that. Fail.Inhesion
Something must be messed up with your Firefox. I just opened a page which changes every page load and the view source is always the same as the current page. Why on earth would FF issue another GET request anyway when it already has the code in memory? If it does, it sounds like a bug to me!Ovular
@Ovular I too noticed that "View Source" was creating a new HTTP request. It turned out that something was indeed messed up with my Firefox -- caching was disabled, so there was no cache to read from! Specifically, the following preferences in about:config had been set to false: browser.cache.disk.enable and browser.cache.memory.enable. Once I set them back to true (which is of course the default), then I was able to verify with HTTPFox that the view-source requests were reading from the cache instead of making a new request.Remarque
Why does Firefox do that? Anybody knows?Boyhood
I ran into this issue too in Firefox. I confirmed with Chrome that it wasn't my application. Setting the cache to 'true' in about:config didn't solve my problem. Solution I used was deleting prefs.js in your firefox profiles.Aerosphere
@SeanBright inspect element views the generated DOM after the browser has parsed the html, so it is impossible to view the original source that wayRoturier
About POST this is still a big yet not solved thing. I will probably make a new question for that later...Sweeping
This may have been silently fixed earlier this year with Firefox 92.0.Locoism
F
-1

This solution was ok in 2012, but no longer nowadays.

Type "about:config" in the address bar. In the filter box, type : "browser.cache" "browser.cache.disk.enable" and "browser.cache.memory.enable" must be set to TRUE. Done ! All credit to @MatrixFrog

Firstfoot answered 11/4, 2012 at 9:54 Comment(2)
As of FF15.0 this does not work. It still does re-request the page to view the source.Ornery
Seems like a bug that's been around for years bugzilla.mozilla.org/show_bug.cgi?id=307089Badman
T
27

If you install the web developer toolbar extension, there's an option under "View Source" called "View Generated Source" which will show you the current source of the page, including any DOM changes you may have made.

Tatouay answered 4/3, 2009 at 17:32 Comment(3)
That's what I came here to post :) Voted you up.Ailey
As you can see, I mentioned this (if obliquely) in my original post. See my comment on the question its self, please.Inhesion
That is an altered source.Locoism
U
21

You do a Ctrl+A, right click and "view selection source", that doesn't re-request the page.

Undervest answered 4/3, 2009 at 17:29 Comment(5)
This appears to be exactly what "View Generated Source" in the web developer toolbar does.Felonious
When I use this, then do F5, does it refresh the view, or send another request?Salad
5 years later your tip is still useful :)Pitcher
This is not the original source.Locoism
Except it is not the real source. It is the post rendered HTML which if you use a client side library like Vue it is totally different than the source the browser received initially. I want to see the original source unaltered.Modernize
A
4

"View Generated Source" is not the same source code you get with "View Source".

View Generated Source "improves" the code, parsing the html, adding newlines among tags, changing attributes order (width="100%" cellpadding="0" => cellpadding="0" width="100%"), adding attributes values (nowrap => nowrap="nowrap") and tags (tbody from nowhere), etc.

You might think this is better, but if you want to compare the old generated source with the actual file, it's useless.

Your best bet is search the directory cache.

Regards

Anamorphism answered 16/11, 2010 at 21:53 Comment(1)
While this clarity in response to other answers is useful, it is not an answer to the question at hand.Locoism
P
2

Use the FireBug extension. It displays (and allows you to navigate) only the rendered source, so there is no need for another request (and it shows Javascript changes).

Pym answered 4/3, 2009 at 17:33 Comment(2)
Rendered source is different than original http response. There's a reason I would look for the latter specifically.Salad
Yes, we are looking for original source not rendered source. The rendered source is already available in the Inspector tab of the browser's dev tools.Modernize
S
1

It is upsetting. An alternative to the methods above is to open the debugger using F12, then click the Network tab.

When you browse to different pages, each GET/POST is shown. You can then click on which post you want, and click the Response tab to see the data that was received by the browser.

Stream answered 17/4, 2015 at 10:47 Comment(4)
That's nice... Except the solution everyone is looking for is to avoid clicking around and just get the real source of the page on the screen when you hit Ctrl-U.Turf
@SteveHorvath - if you have the debug window already open when you view the page, you literally click on it to see the source code, its not hard. And unless you're living in the 80's, most pages are made up of many sub calls, and data XHR calls, all shown in the network tab for easy browsing. Interesting to see how certain you are on what "Everyone" on the internet is searching for though LOL!! LOL. Mercy.Stream
Almost always the network tab is not populated so you have to refresh the page, then find the resource in question from a list of dozens, then drill down with several mouse clicks. It's a total pain but seems to be the only solution that works.Modernize
This is the best answer, until (if) it gets fixed in Firefox sometime in the future. If you have trouble finding the correct request, it's usually the top one, if you did not enable persistence. If you did, you can filter by URL to find the correct request. If you did not have devtools already open, you are out of luck and have to repeat the request anyway.Electrolyse
A
0

To extend @Techn4k's answer: If you have those two properties set, but still get the re-GET or re-POST behavior, clear your browser cache: Go to about:preferences#advanced, click on the network tab, and click clear now (or similar) on the cache information part.

This lets Firefox fetch and cache the page, so that no re-GET or re-POST appears.

Anglia answered 19/2, 2015 at 13:2 Comment(0)
L
0

Despite being broken for at least sixteen solid years, and continuing to be officially unresolved on Mozilla's bug tracker, this actually seems to have been silently fixed with the release of Firefox 92.0, released on September 17, 2021.


Previous answer:

This is broken in Firefox for some time now:

https://bugzilla.mozilla.org/show_bug.cgi?id=307089

They aren't very responsive on their bug tracker, but your options are:

(1) complain at the bug tracker,
(2) fix it yourself it's open source software,
(3) find another browser.

Locoism answered 15/6, 2017 at 16:52 Comment(5)
No, it is not fixed in Firefox 101. It behaves as OP describes, requesting a new page.Ankylostomiasis
@MarkJeronimus Wouldn't surprise me at all if it was broken again between 92 & 101. If you check the Mozilla bug, they were not aware of it as broken or fixed either.Locoism
I confirm that this is not fixed as of Firefox 121.Electrolyse
@MarkJeronimus I'm not setup to reevaluate this, but if you feel like editing this answer that is fine by me.Locoism
@JanPokorný also ^ (Only one person can be notified? Sheesh.)Locoism
F
-1

This solution was ok in 2012, but no longer nowadays.

Type "about:config" in the address bar. In the filter box, type : "browser.cache" "browser.cache.disk.enable" and "browser.cache.memory.enable" must be set to TRUE. Done ! All credit to @MatrixFrog

Firstfoot answered 11/4, 2012 at 9:54 Comment(2)
As of FF15.0 this does not work. It still does re-request the page to view the source.Ornery
Seems like a bug that's been around for years bugzilla.mozilla.org/show_bug.cgi?id=307089Badman
Y
-2

You can just set Firefox into Offline mode before issuing View Source command. It will not (be able to ) get a fresh page source.

Yeeyegg answered 14/12, 2016 at 10:21 Comment(1)
Or any source at all.Locoism
E
-3

This is an older question but it still happens from time to time depending on what they have currently broken in the latest Firefox or what subtle extension bug is causing conflicts.

I wanted to post a workaround that seems to work for me consistently, because in the end we have to get work done and not spend hours trying to fix this.

Simply add view-source: to the beginning of the url and it will show the source with the get/post data that you are trying to use.

ie.

view-source:http://stackoverflow.com/

Not a true solution but a work-around to get work done.

Ermelindaermengarde answered 22/12, 2012 at 7:20 Comment(3)
This results in the same fresh GET-request for me.Fleming
This doesn't work. Same faulty result as the view source option in the context menu.Modernize
While it wasn't true at the time, this should actually work with versions of Firefox 92 to current (95 at time of writing), although using the ordinary View Source menu item or keyboard shortcut should also work, and is more straightforward.Locoism
A
-3

From Firefox 42.0 onwards, clicking "View source" should not do a new GET request but use the cache:

Importantly, we have also ensured that View Page Source provides you with the source of the page as-is from Firefox’s cache – we do not fetch a new version.

Reference: https://hacks.mozilla.org/2015/07/developer-edition-41-view-source-in-a-tab-screenshot-elements-har-files-and-more/

Arctogaea answered 20/1, 2016 at 16:57 Comment(2)
However it does do a new request.Locoism
While it wasn't true for version 42, this seems to be true again from Firefox version 92 to current (95 at time of writing).Locoism
R
-3

Open the dev console (with F12, "Inspect Element" in the right-click menu, etc.) and navigate to the Inspector tab. Right click anywhere in the panel showing the DOM tree and click "Expand All". Scroll to the very top of the DOM tree and right-click the <html> tag. Click "Edit as HTML" and the entire DOM tree should appear in an editable text box. This should now be selectable with Ctrl+A. Copy and paste into the destination of your choice.

Bear in mind that if the source itself contains URLs, e.g. imports styles from a CDN, that means your copy of the page still won't load independently and will look different if you can't access those assets. It'll be an exact copy of the page's original logic, plus your changes.

Reggie answered 5/12, 2019 at 12:8 Comment(1)
Not the answer to the question.Modernize

© 2022 - 2024 — McMap. All rights reserved.