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?

Ben Hamill
  • 2,661
  • 2
  • 19
  • 18
  • 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. – Sean Bright Mar 04 '09 at 17:32
  • 5
    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. – Ben Hamill Mar 04 '09 at 21:28
  • 1
    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! – DisgruntledGoat Mar 06 '09 at 00:50
  • 4
    @DisgruntledGoat 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. – Tyler Oct 05 '10 at 00:51
  • 3
    Why does Firefox do that? Anybody knows? – Agis Apr 04 '13 at 11:03
  • 1
    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. – bunwich Jun 25 '13 at 19:07
  • 1
    @SeanBright inspect element views the generated DOM after the browser has parsed the html, so it is *impossible* to view the original source that way – chiliNUT Sep 17 '14 at 20:24
  • 2
    About POST this is still a big yet not solved thing. I will probably make a new question for that later... – Matteo B. Nov 26 '14 at 11:39
  • This may have been silently fixed earlier this year with Firefox 92.0. – Jan Kyu Peblik Dec 29 '21 at 20:17

12 Answers12

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.

TJ L
  • 23,914
  • 7
  • 59
  • 77
20

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

Paul Dixon
  • 295,876
  • 54
  • 310
  • 348
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

German
  • 67
  • 1
  • 3
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).

qpingu
  • 950
  • 7
  • 11
  • 8
    Rendered source is different than original http response. There's a reason I would look for the latter specifically. – JNF Dec 10 '12 at 08:18
  • 1
    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. – Brobic Vripiat Mar 06 '21 at 19:27
1

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.

Jan Kyu Peblik
  • 1,435
  • 14
  • 20
  • No, it is not fixed in Firefox 101. It behaves as OP describes, requesting a new page. – Mark Jeronimus Jul 17 '22 at 08:13
  • @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. – Jan Kyu Peblik Jul 20 '22 at 03:49
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.

Boldewyn
  • 81,211
  • 44
  • 156
  • 212
0

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.

Tom Chamberlain
  • 2,955
  • 20
  • 24
  • 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. – Steve Horvath Dec 11 '18 at 02:01
  • @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. – Tom Chamberlain Dec 11 '18 at 17:01
  • 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. – Brobic Vripiat Mar 06 '21 at 19:39
-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

TeChn4K
  • 2,317
  • 2
  • 21
  • 23
-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.

-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.

ck_
  • 3,353
  • 5
  • 31
  • 33
-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/

Flimm
  • 136,138
  • 45
  • 251
  • 267
-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.

Tranquilled
  • 139
  • 6