55

When executing a script directly in the console in Chrome, I saw this:

enter image description here

Does anyone know what's the meaning of VM117:2

What does VM stand for ?

edi9999
  • 19,701
  • 13
  • 88
  • 127
  • 3
    Possible duplicate of http://stackoverflow.com/questions/17367560/chrome-development-tool-vm-file-from-javascript – Ethan Selzer Dec 05 '13 at 00:23
  • 6
    is there a way to remove it/disable printing it? often totally useless for me. i just want to copy links or data from the console, mostly logged XHRs. – computingfreak Jan 20 '17 at 01:11
  • @computingfreak This is a shot in the dark since the comment thread is so old, but have you managed to figure out how to disable it? I'm getting it printed 20+ times for every page load and it's driving me crazy! – MRB Apr 09 '21 at 17:52
  • 1
    @MRB I found a solution, added as an answer to this question - please check at https://stackoverflow.com/a/67026569/1818089 – computingfreak Apr 09 '21 at 18:34
  • 1
    @MRB not sure whether my answer would be kept, please see https://stackoverflow.com/questions/36009071/how-to-omit-file-line-number-with-console-log, and acknowledge somehow. – computingfreak Apr 09 '21 at 18:42
  • @computingfreak I am so appreciative that you responded! I was more so wondering if you had figured out how to disable the debugger from logging. My debugger is running 20+ times in a row and filling the console w/ print statements. More explained here: https://stackoverflow.com/questions/67024539/how-to-stop-chrome-devtools-debugger-from-logging-repeatedly-in-the-console – MRB Apr 10 '21 at 12:50

2 Answers2

55

It is abbreviation of the phrase Virtual Machine. In the Chrome JavaScript engine (called V8) each script has its own script ID.

Sometimes V8 has no information about the file name of a script, for example in the case of an eval. So devtools uses the text "VM" concatenated with the script ID as a title for these scripts.

Some sites may fetch many pieces of JavaScript code via XHR and eval it. If a developer wants to see the actual script name for these scripts she can use sourceURL. DevTools parses and uses it for titles, mapping etc.

Eliran Malka
  • 15,821
  • 6
  • 77
  • 100
loislo
  • 14,025
  • 1
  • 28
  • 24
2

Thanks to @MRB,

I revisited this problem, and found the solution today, thanks to https://stackoverflow.com/a/63221101/1818089

queueMicrotask (console.log.bind (console, "Look! No source file info..."));

It will group similar elements, so make sure you add a unique identifier to each log line to be able to see all data.

enter image description here

Demonstrated in the following example.

Instead of

data = ["Apple","Mango","Grapes"];
for(i=0;i<10;i++){
    queueMicrotask (console.log.bind (console, " info..."+i));
}

use

data = ["Apple","Mango","Grapes"];
for(i=0;i<data.length;i++){
    queueMicrotask (console.log.bind (console, " info..."+i));
}

A better way would be to make a console.print function that does so and call it instead of console.log as pointed out in https://stackoverflow.com/a/64444083/1818089

// console.print: console.log without filename/line number
console.print = function (...args) {
    queueMicrotask (console.log.bind (console, ...args));
}

Beware of the grouping problem mentioned above.

enter image description here

Dharman
  • 30,962
  • 25
  • 85
  • 135
computingfreak
  • 4,939
  • 1
  • 34
  • 51