1

Color does not work for links in the console, how can this be fixed? The first two lines are displayed fine, but the third line is not working correctly:

console output

console.log('%cHello-hello-hello', 'color: #5865f2; font: 700 68px sans-serif;-webkit-text-stroke: 2px black;');
console.log('%cat the link below', 'color: #5865f2; font: 700 24px sans-serif;');
console.log('%chttps://stackoverflow.com/', 'color: #000; font: 700 18px sans-serif;');
Hooxy
  • 63
  • 5
  • A quite similar question has been asked here https://stackoverflow.com/questions/49728760/style-links-in-javascript-console – Ahmad Habib Jul 19 '21 at 11:24
  • `console.log('%c https://'+'%cstackoverflow.com/', "color: #5865f2; font: 700 18px sans-serif;", "color: #5865f2; font: 700 18px sans-serif;");` – Lawrence Cherone Jul 19 '21 at 12:17

3 Answers3

0

Check applied color its black. Try this i have applied other color in link and it's working fine

console.log('%chttps://stackoverflow.com/', 'color: #5865f2; font: 700 18px sans-serif;');

enter image description here

0

Unfortunately if the string is a full URL there's some default behaviour you can't override the solution Is to only pass the hostname without the HTTP protocol and manually append the protocol as a string before the hostname.

This should work

const css = "color: #000; font: 700 18px sans-serif;"
console.log('%c https://'+'%cstackoverflow.com/', css, css);

enter image description here

Josh
  • 459
  • 5
  • 10
0

This seems to be by design as pointed out in this comment:

// Make sure that allowed properties do not interfere with link visibility.

https://github.com/ChromeDevTools/devtools-frontend/blob/ef157dab2ccf321941548a51d350f9383a78d283/front_end/panels/console/ConsoleViewMessage.ts#L928

This makes sense so links cannot be hidden in the console.

Seblor
  • 6,947
  • 1
  • 25
  • 46