Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When viewing page source in Google Chrome, the browser opens a new tab and basically pastes the URL in with the view-source: prefix. This is undesirable.

As a developer, I may include some diagnostic output that is only visible in the source after submitting a form. When Chrome Refreshes the page to view the source, it makes this information disappear.

Is there anyway to prevent this behavior?

Note: I'm familiar with the "Inspect Element" option. This is just not an adequate stand-in for viewing the raw page source of the exact page you're looking at.


A quick test script

<pre>
  <?= print_r($_POST, true) ?>
</pre>
<form action="" method="post">
  <input id="foo" name="foo" value="bar" />
  <input type="submit" />
</form>

After clicking the submit button, the page shows

Array
(
    [foo] => bar
)

If you view page source, you will see an empty $_POST output

<pre>
Array
(
)
</pre>
<form action="" method="post"> 
  <input id="foo" name="foo" value="bar" /> 
  <input type="submit" /> 
</form> 

Update

Apparently this bug has already been submitted. Sigh...

If anyone knows of a good work around, I'd greatly appreciate it.

share|improve this question
    
The people there do not understand that the source is not kept in memory (due to minimalism) but manipulated. You should see the comment code.google.com/p/chromium/issues/detail?id=523#c47 as that seems a nice idea too... –  Tom Wijsman Aug 7 '10 at 9:10

2 Answers 2

up vote 7 down vote accepted

From the bug report page, the workaround mentioned in comment 12 works: In the Developer Tools, enable Resource Tracking. (If it was off, enabling it will resubmit the request that generated the currently visible page, either POST or GET.) In the list of Resources, you can click on the main page to see the source code as it was returned by sever the for both POST and GET requests.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

More information

I ran some tests using a simple php file that showed the request method used and a POSTed value, a proxy server log to see which requests Chrome was making, and the chrome://net-internals/view-cache/ prefix to see what Chrome was caching.

When you use the View Source command, Chrome shows the source of its cached version of the page, and it only caches pages requested via the GET method.

If you're looking at a page that you've previously requested using GET and POST, then only the GET version is cached. Using the View Source command won't re-request the page, but will show the cached GET version, not the currently visible POST version, if any.

If you're looking at a page that you've only requested using the POST method, then using the View Source command will cause Chrome to look in its cache, find nothing, request the page using GET, cache it, and show the source of that.

share|improve this answer
    
Nice discovery! –  Tom Wijsman Aug 9 '10 at 17:46
1  
Chrome has changed a lot since this answer but it's basically the same: open dev tools, ensure that network traffic is recorded and find the request that was logged in the Network tab. In the case of redirected requests you can check "Preserve log" or "preverse log upon navigation" to not erase the log with each new sync request. –  Jon z Dec 26 '13 at 15:48
    
@Jonz after realising this folly I am already disliking Google Chrome. For e.g. I needed to check the page source of Thank you page of E-commerce website (page loaded after user makes a successfull payment, for checking the firing of GTM code). Now on load of the page, I simply unset the necessary session and again on reload if the session is not found, I redirect the user to home page. So if I try to use Google Chrome hack, I am never able to view the page source, because it can only resend the GET and POST request, but it can't reset the session. Hence I would suggest use "Inspect Element" –  Abhishek Madhani Jun 4 at 12:37
    
@AbhishekMadhani I'm not sure that you meant to reply to me, but I'll repeat what I wrote in a comment below - it seems that, as of Chrome Canary 37, a new network request is not sent when you view the source. –  Jon z Jun 12 at 18:25

I'm sorry to tell you, but this is against the current nature of browsing and debugging in a browser...

The original source is not kept in memory, but is parsed and transformed into a parse tree as fast as possible, this to prevent useless memory usage. Thus, any debugging information you hide in the source is lost and must be explicitly requested. In the so-called Web 2.0 sites, elements also change and that is the reason the inspection is like that...

Solution 1: Fiddler Web Debugger allows you to inspect HTTP traffic,
this allows you to see the debug information from your last request.

Solution 2: Embed your debugging information or append it at the end,
or maybe show it as a pop-up or in another awesome way that doesn't disturb your lay-out.

share|improve this answer
1  
+1 - better than mine! –  JNK Aug 6 '10 at 19:29
7  
TomWij, "this is against the current nature of browsing and debugging in a browser..." this is just plain inaccurate. Current versions of Firefox and Safari both behave as "expected". In fact, because I've used these features in other browsers, I've come to expect them in Chrome. Keeping a couple KB of plain text for the original source in memory should be no difficulty. –  macek Aug 6 '10 at 19:44
    
Google Chrome is known for its minimalism. ;-) –  Tom Wijsman Aug 7 '10 at 9:04
1  
No doubt, and that is where View Source should read from also. A new request is simply misleading and wrong. –  Chris Dec 18 '13 at 16:11
1  
@Jonz Are you arguing to remove the View Source function altogether? I'd support this if the only alternative is the current broken implementation. But why can't we have both? Clicking through the network logs in the dev toolbar is a great option to have when you need that level of information, but if you just want to see the source for the current page it seems overkill. –  Chris Jan 2 at 17:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.