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

8.1k Views Asked by At

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?

12

There are 12 best solutions below

2
On BEST ANSWER

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

1
On

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

1
On

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.

5
On

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

3
On

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.

2
On

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

1
On

"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

4
On

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.

0
On

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.

3
On

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.

5
On

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.

2
On

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/