IT技术博客大学习 共学习 共进步

警惕 Chrome 的查看源代码 (View Page Source) 功能

qingbo.blog 2012-04-22 14:46:31 浏览 7,043 次

    前阵子解决一个问题的时候,差点以为是我们自己在 HTML 代码中输出的一段信息有问题,结果发现,Chrome 的 View Source Code 竟然会重新发送一个请求!

    有史以来,所有的浏览器从来没有过这样天才的设计。大家都是老老实实,既然你让我显示源代码,那我就直接给你把正在看的这个页面的源代码显示出来。没有人想过竟然可以重新发起一个请求,去拿“纯洁的”源代码。这是革命性的!Chrome 你做到了!

    早在2008年,就已经有人提出这个 bug - View source forces page reload. 中间有人将之标记过 Fixed,但是世界末日快来了,Chrome 的稳定版本已经飚到18了,市场份额已经远超 Firefox 了,实际上这个 bug 仍然存在。我的天啊,究竟是什么样的设计,导致解决这样一个问题这么难?

    甚至还曾有开发者认为 View Source 就应该是这样的行为 (链接):

    Yes, when you "view source", you\'re really opening a new tab that opens the page again and displays the source rather than renders the page. Many web pages are dynamic and modify their HTML content (eg. using JavaScript/XMLHttpRequest) so we cannot display the current HTML - this is why a new request is made.

    If you want to view the current state of a dynamic page, you should use the inspector. "File icon -> Developer -> JavaScript console"

    I don\'t see how this is a security bug or a bug at all - the behavior is by design - closing as such.

    注意里面加粗倾斜的那段话——因为很多网页是动态的,所以无法显示当前的 HTML,所以发送一个新的请求。这逻辑真够奇怪的!你是想“显示当前的 HTML”吗?你发送一个新的请求解决了这个问题吗?没有解决,那你何必要发一个新的请求?这就相当于脱了裤子,屁还是没有放出来。

建议继续学习

  1. Chrome和goagent的配置方法,你懂的 (阅读 16,622)
  2. 看源代码那些事 (阅读 10,460)
  3. webapp网页调试工具Chrome Devtools (阅读 6,782)
  4. [译]Google Chrome中的高性能网络 (阅读 6,502)
  5. 我自己研究开源项目源代码的两个重要习惯 (阅读 5,841)
  6. 通过使用Chrome的开发者工具来学习JavaScript (阅读 5,763)
  7. chrome扩展应用开发教程之开发chrome应用基础 (阅读 5,602)
  8. 如何制作chrome扩展程序 (阅读 5,560)
  9. Chrome开发者工具的小技巧 (阅读 5,043)
  10. 如何创建google浏览器插件 (阅读 4,961)