Search code examples
javascriptchromiumv8

Does Chromium pass URLs along with JS to V8?


I've added a print statement to v8/src/parsing/parsing.cc to output JS source code before compilation to deobfuscate code. I also want to print the URL associated with the JS if it exists.

There are objects, such as source_url, in parser.cc and scanner.cc that and would appreciate advice about extracting the URL from them if they actually contain that information.

If they don't contain JS source URLs where should I look elsewhere in Chromium source code?


Solution

  • The source_url that the scanner passes to the parser only reflects explicit "sourceURL" comments in the source; any code that needs deobfuscation probably won't have those.

    To get the script URL, you'll want to look at v8::internal::Script::name(). It can be a v8::internal::String, or undefined if the embedder (i.e. Chromium) didn't provide a name for the given script -- which can in particular happen when the script doesn't have a name/URL, such as when it comes from the DevTools console or a dynamically-generated source string.