5

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

 3 years ago
source link: https://blogread.cn/it/article/5234?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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

浏览:5307次  出处信息

    前阵子解决一个问题的时候,差点以为是我们自己在 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”吗?你发送一个新的请求解决了这个问题吗?没有解决,那你何必要发一个新的请求?这就相当于脱了裤子,屁还是没有放出来。

建议继续学习:

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK