tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 01a75a80dab2e2154f744937f5832baa9abcba43
parent 5599774de8c4db1b22ceb89b948ae2f6a9939788
Author: Nazım Can Altınova <canaltinova@gmail.com>
Date:   Tue, 21 Oct 2025 23:59:09 +0000

Bug 1916785 - Add a GET_JS_SOURCES WebChannel request for frontend to fetch sources r=mstange,profiler-reviewers

As the last step, now we implement the WebChannel request, which will be
used by the frontend.

Differential Revision: https://phabricator.services.mozilla.com/D259272

Diffstat:
Mdevtools/client/performance-new/@types/perf.d.ts | 12++++++++++--
Mdevtools/client/performance-new/shared/background.sys.mjs | 28+++++++++++++++++++++++++++-
2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/devtools/client/performance-new/@types/perf.d.ts b/devtools/client/performance-new/@types/perf.d.ts @@ -481,7 +481,8 @@ export type RequestFromFrontend = | GetSymbolTableRequest | QuerySymbolicationApiRequest | GetPageFaviconsRequest - | OpenScriptInTabDebuggerRequest; + | OpenScriptInTabDebuggerRequest + | GetJSSourcesRequest; type StatusQueryRequest = { type: "STATUS_QUERY" }; type EnableMenuButtonRequest = { type: "ENABLE_MENU_BUTTON" }; @@ -517,6 +518,10 @@ type OpenScriptInTabDebuggerRequest = { line: number; column: number; }; +type GetJSSourcesRequest = { + type: "GET_JS_SOURCES"; + sourceUuids: Array<string>; +}; export type MessageToFrontend<R> = | OutOfBandErrorMessageToFrontend @@ -549,7 +554,8 @@ export type ResponseToFrontend = | GetSymbolTableResponse | QuerySymbolicationApiResponse | GetPageFaviconsResponse - | OpenScriptInTabDebuggerResponse; + | OpenScriptInTabDebuggerResponse + | GetJSSourcesResponse; type StatusQueryResponse = { menuButtonIsEnabled: boolean; @@ -580,6 +586,8 @@ type GetSymbolTableResponse = SymbolTableAsTuple; type QuerySymbolicationApiResponse = string; type GetPageFaviconsResponse = Array<ProfilerFaviconData | null>; type OpenScriptInTabDebuggerResponse = void; +type GetJSSourceReponseItem = { sourceText: string } | { error: string }; +type GetJSSourcesResponse = Array<GetJSSourceReponseItem>; /** * This represents an event channel that can talk to a content page on the web. diff --git a/devtools/client/performance-new/shared/background.sys.mjs b/devtools/client/performance-new/shared/background.sys.mjs @@ -36,7 +36,7 @@ const POPUP_FEATURE_FLAG_PREF = "devtools.performance.popup.feature-flag"; // capabilities of the WebChannel. The front-end can handle old WebChannel // versions and has a full list of versions and capabilities here: // https://github.com/firefox-devtools/profiler/blob/main/src/app-logic/web-channel.js -const CURRENT_WEBCHANNEL_VERSION = 5; +const CURRENT_WEBCHANNEL_VERSION = 6; const lazyRequire = {}; // eslint-disable-next-line mozilla/lazy-getter-object-name @@ -344,7 +344,33 @@ async function getResponseForMessage(request, browser) { const { openScriptInDebugger } = lazy.BrowserModule(); return openScriptInDebugger(tabId, scriptUrl, line, column); } + case "GET_JS_SOURCES": { + const { sourceUuids } = request; + if (!Array.isArray(sourceUuids)) { + throw new Error("sourceUuids must be an array"); + } + + const infoForBrowser = infoForBrowserMap.get(browser); + if (infoForBrowser === undefined) { + throw new Error("No JS source data found for this tab"); + } + const jsSources = infoForBrowser.jsSources; + if (jsSources === null) { + return sourceUuids.map(() => ({ + error: "Source not found in the browser", + })); + } + + return sourceUuids.map(uuid => { + const sourceText = jsSources[uuid]; + if (!sourceText) { + return { error: "Source not found in the browser" }; + } + + return { sourceText }; + }); + } default: { console.error( "An unknown message type was received by the profiler's WebChannel handler.",