有没有办法破解console.log的解决方案 [英] Is there a way to work-around site(s) breaking console.log

查看:147
本文介绍了有没有办法破解console.log的解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Chrome DevTools控制台摘录:

Excerpt of my Chrome DevTools Console:

Navigated to https://twitter.com/
console.log.toString();
"function (){}"
Navigated to http://linuxfr.org/
console.log.toString();
"function log() { [native code] }"

我设法注入代码在twitter.com的主框架中,使用Chrome扩展程序,但我很难理解为什么我的代码似乎没有运行。似乎我的代码运行正常,除了 console.log 什么都不生成!

I managed to inject code in the main frame of twitter.com, using a Chrome Extension, but I had a hard time understanding why my code seemed to not run. It appears that my code is running fine, except console.log produces exactly nothing!

问题:有没有方式调用现在已经消失 console.log 本机代码?


(关于那种JavaScriptWAT行为缩回,等等)的评论

Question: is there a way to call the "now gone" console.log "native code"?

(remarks about that kind of JavaScript "WAT" behavior retracted, sort of)

推荐答案

由于这是Chrome扩展程序,您将内容脚本设置为 run_at:document_start - 您可以(理论上)抓住 console.log / 错误 / dir / info 等在Twitter获得它的肮脏之手之后

As this is a Chrome Extension, you set your content script to run_at: "document_start" - you can(theoretically) "grab" console.log / error / dir / info etc before twitter gets it's grubby hands on them

实际上,知道twitter只能替换日志,警告,信息,错误,你可以只需这样做:

actually, KNOWING that twitter only replaces log, warn, info, error, you can simply do:

var _console = ['log', 'warn', 'info', 'error'].reduce(function(result, key) { 
    result[key] = console[key].bind(console); 
    return result
}, {});

然后你可以使用 _console.log 和朋友

这篇关于有没有办法破解console.log的解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆