【问题标题】:Console.log without reference to the scriptConsole.log 不参考脚本
【发布时间】:2014-08-30 22:14:37
【问题描述】:

我猜这是一个非常无用的问题,但是在不参考脚本的情况下找出 facebook 如何打印到浏览器控制台真的很有趣。在 facebook.com 打开控制台,您将看到文本,但看不到对 javascript 的引用...

【问题讨论】:

  • 您可以覆盖 JS 函数,只需重新定义它们。 console.log = function(){ /* whatever magic you want */ }
  • @ProstoTrader 这不是一个无用的问题。其实我也对答案很感兴趣..他们是如何做到的很有趣。
  • @ProstoTrader - 你所要做的就是确保开发工具在一个分离的窗口中,你可以检查检查器:) 查看这篇文章了解更多信息:stackoverflow.com/questions/12291138/…
  • 哇!不知道我们可以检查检查器))) 只需更改 css 我们可以隐藏参考 ))) #console-messages .link, #console-messages a { color: transparent;光标:指针; }
  • @ProllyGeek 您不必登录。只需访问 fb url 并检查

标签: javascript facebook console.log


【解决方案1】:

嗯,我朋友的朋友找到了答案。

对于没有引用的console.log,我们应该使用setTimout和bind

setTimeout(console.log.bind(console, 'test'));

这是整个 facebook sn-p:

    var i = "Stop!",
        j = "This is a browser feature intended for developers. If someone told you to copy-paste something here to enable a Facebook feature or \"hack\" someone's account, it is a scam and will give them access to your Facebook account.";

if ((window.chrome || window.safari)) {
var l = 'font-family:helvetica; font-size:20px; ';
[
   [i, l + 'font-size:50px; font-weight:bold; ' + 'color:red; -webkit-text-stroke:1px black;'],
   [j, l],
   ['', '']
].map(function(r) {
    setTimeout(console.log.bind(console, '\n%c' + r[0], r[1]));
});
}

【讨论】:

  • 哇!这真是出乎意料,想知道为什么 facebook 开发人员会这样做?
  • 我可以理解为什么,但我无法真正理解他们是如何做到的。可能其中一个以前在 webInspector 上工作过,并且知道该错误
  • if ((window.chrome || window.safari)) 没用,因为它也适用于例如Firefox。
【解决方案2】:

更通用的功能。
如果使用 () 而不是 ("Your title here","Your text here")
它将显示默认消息。

((title,message)=>{
    var i = title || "Stop!"
      , j = message || "This is a browser feature intended for developers. If someone told you to copy-paste something here to enable a Facebook feature or \"hack\" someone's account, it is a scam and will give them access to your Facebook account.";

    var l = 'font-family:helvetica; font-size:20px; ';
    [[i, l + 'font-size:50px; font-weight:bold; ' + 'color:red; -webkit-text-stroke:1px black;'], [j, l], ['', '']].map(function(r) {
        setTimeout(console.log.bind(console, '\n%c' + r[0], r[1]));
    });
})("Your title here","Your text here")

或直接:

console.alert = function(title, message) {
  var i = title || "Stop!",
    j = message || "This is a browser feature intended for developers. If someone told you to copy-paste something here to enable a Facebook feature or \"hack\" someone's account, it is a scam and will give them access to your Facebook account.";

  var l = 'font-family:helvetica; font-size:20px; ';
  [
    [i, l + 'font-size:50px; font-weight:bold; ' + 'color:red; -webkit-text-stroke:1px black;'],
    [j, l],
    ['', '']
  ].map(function(r) {
    setTimeout(console.log.bind(console, '\n%c' + r[0], r[1]));
  });
}

console.alert("Hello", "You can write what you like here!")

【讨论】:

  • 不能在 Angular 10 中工作,可能会返回及以上版本
猜你喜欢
  • 2011-11-07
  • 1970-01-01
  • 2013-10-05
  • 2014-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-18
相关资源
最近更新 更多