Javascript Tampermonkey console.log不';t似乎与chrome开发工具中的相同

Javascript Tampermonkey console.log不';t似乎与chrome开发工具中的相同,javascript,tampermonkey,Javascript,Tampermonkey,这就是我到目前为止所做的: 函数加载脚本(url){ 返回新承诺((解决、拒绝)=>{ 让script=document.createElement('script'); script.onload=函数(){ 解决(); }; script.src=url; document.head.appendChild(脚本); }); }; 加载脚本(“https://rawgit2.com/icodeforlove/template-colors-web/master/dist-browser/te

这就是我到目前为止所做的:

函数加载脚本(url){
返回新承诺((解决、拒绝)=>{
让script=document.createElement('script');
script.onload=函数(){
解决();
};
script.src=url;
document.head.appendChild(脚本);
});
};
加载脚本(“https://rawgit2.com/icodeforlove/template-colors-web/master/dist-browser/template-colors.js)然后(加载);
函数加载(){
函数日志(pkt){
pkt=pkt.join(',');
log(c`${['.red.bold}${pkt.green.bold}${']'.red.bold}`);
};
logThing([“Test”,“thing”,“here”]);
}
通常,在开发工具控制台中,它的日志如下所示:

但对于tampermonkey,它记录了以下内容:

为什么猴子会这样做?我到底该怎么解决这个问题呢

还要记住,不使用console.log的情况如下:

使用
@require
加载脚本:

// ==UserScript==
// @name         StackOverflow question 66604679
// @version      0.1
// @author       Wolfy
// @match        https://stackoverflow.com/questions/66604679/tampermonkey-console-log-doesnt-seem-to-be-the-same-as-the-one-in-chrome-dev-to
// @require      https://rawgit2.com/icodeforlove/template-colors-web/master/dist-browser/template-colors.js
// @grant        none
// ==/UserScript==
/* globals c */

(function() {    
  function logThing(wordsArray) {
    const stringToPrint = wordsArray.join(',');
    console.log(c`${'['.red.bold}${stringToPrint.green.bold}${']'.red.bold}`);
  }
  logThing(['Test', 'thing', 'here']);
})();

原因是在您的脚本中,
是在页面上下文中添加的,因此它不会修补TM的控制台。

看起来像是Tampermonkey中的一个bug。作为一种解决方法,您可以从虚拟iframe中提取原始console.log。