Chrome Devtools控制台无法在某些网站中使用

del*_*les 3 javascript google-chrome google-chrome-devtools

我正在使用Twitter网站进行一些Javascript研究.在任何网站中,我都可以打开Goog​​le Devtools并使用控制台来操作页面上的任何内容,例如获取DOM节点,编辑元素等.

例如,当我打开"www.google.com"时,请转到Devtools并输入上面的命令:

的console.log( '试验');

我在控制台中显示"测试"字符串.

在此输入图像描述

然而,当我打开'www.twitter.com'并做同样的事情时,没有发生.控制台中没有显示任何内容,只是一个'undefined'字符串,如下所示:

在此输入图像描述

为什么这种行为只发生在Twitter网站上?

编辑:尝试解决"删除"提出的解决方案 - 恢复本机功能不适用于更改原型,怎么样?

但没有奏效:

在此输入图像描述

Fab*_*nes 6

在Javascript中,您可以修改全局对象,因此您可以执行类似的操作

Array.prototype.push = function(element) {
  this[this.length] = 'blah'
}
Run Code Online (Sandbox Code Playgroud)

现在,每次向任何数组添加元素时,它总是会添加'blah';

const myArray = [];
myArray.push(1);
myArray.push(2);
myArray.push(3);
console.log(myArray);
// output ['blah', 'blah', 'blah']
Run Code Online (Sandbox Code Playgroud)

在Twitter网站上他们做了同样的事情,虽然代码缩小了,你可以在这里看到它:

, Y = ["log", "warn", "debug", "info"]
, K = function() {}
, Q = ""
Run Code Online (Sandbox Code Playgroud)

第1414行文件https://abs.twimg.com/k/en/init.en.caa653749241467e7dbb.js

要使其再次工作,请复制每一行并在控制台上运行(将此解决方案归功于Rob W):

var frame = document.createElement('iframe');
document.body.appendChild(frame);
console = frame.contentWindow.console
console.log('it works')
Run Code Online (Sandbox Code Playgroud)