LibWebView+test-web: Print heap explorer URL after dumping GC graph

When dumping a GC graph, we now write the output as a .js file
containing `var GC_GRAPH_DUMP = <json>;` instead of raw JSON.
This allows gc-heap-explorer.html to load the dump via a
dynamically created <script> element, avoiding CORS restrictions
that prevent file:// pages from fetching other file:// URLs.

After dumping, both the browser and test-web print a clickable
file:// URL that opens the heap explorer with the dump pre-loaded.

The heap explorer's drag-and-drop file picker also accepts both
the new .js format and plain .json files.
This commit is contained in:
Andreas Kling
2026-02-01 20:52:16 +01:00
committed by Andreas Kling
parent 34ae80d602
commit 64d033b31a
Notes: github-actions[bot] 2026-02-06 10:47:20 +00:00
4 changed files with 52 additions and 6 deletions

View File

@@ -806,10 +806,13 @@ ErrorOr<LexicalPath> ViewImplementation::dump_gc_graph()
auto gc_graph_json = TRY(promise->await());
LexicalPath path { Core::StandardPaths::tempfile_directory() };
path = path.append(TRY(AK::UnixDateTime::now().to_string("gc-graph-%Y-%m-%d-%H-%M-%S.json"sv)));
path = path.append(TRY(AK::UnixDateTime::now().to_string("gc-graph-%Y-%m-%d-%H-%M-%S.js"sv)));
// Write as a .js file so gc-heap-explorer.html can load it via <script> tag (avoiding CORS issues with file:// URLs)
auto dump_file = TRY(Core::File::open(path.string(), Core::File::OpenMode::Write));
TRY(dump_file->write_until_depleted("var GC_GRAPH_DUMP = "sv.bytes()));
TRY(dump_file->write_until_depleted(gc_graph_json.bytes()));
TRY(dump_file->write_until_depleted(";\n"sv.bytes()));
return path;
}