/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ // @ts-check "use strict";
/** *Onceaprofileisreceivedfromtheactor,itneedstobeopenedupin *profiler.firefox.comtobeanalyzed.Thisfunctionopensupprofiler.firefox.com *intoanewbrowsertab. * *@typedef{object}OpenProfilerOptions *@property{ProfilerViewMode|undefined}[profilerViewMode]-ViewmodefortheFirefoxProfiler *front-endtimeline.Whileopeningtheurl,weshouldappendaquerystring *ifaviewotherthan"full"needstobedisplayed. *@property{ProfilerPanel}[defaultPanel]Allowstochangethedefaultopenedpanel. * *@param{OpenProfilerOptions}options *@returns{Promise<MockedExports.Browser>}Thebrowserfortheopenedtab.
*/
async function openProfilerTab({ profilerViewMode, defaultPanel }) { // Allow the user to point to something other than profiler.firefox.com. const baseUrl = Services.prefs.getStringPref(
UI_BASE_URL_PREF,
UI_BASE_URL_DEFAULT
); // Allow tests to override the path. const baseUrlPath = Services.prefs.getStringPref(
UI_BASE_URL_PATH_PREF,
UI_BASE_URL_PATH_DEFAULT
); const additionalPath = defaultPanel ? `/${defaultPanel}/` : ""; // This controls whether we enable the active tab view when capturing in web // developer preset. const enableActiveTab = Services.prefs.getBoolPref(
UI_ENABLE_ACTIVE_TAB_PREF, false
);
// We automatically open up the "full" mode if no query string is present. // `undefined` also means nothing is specified, and it should open the "full" // timeline view in that case.
let viewModeQueryString = ""; if (profilerViewMode === "active-tab") { // We're not enabling the active-tab view in all environments until we // iron out all its issues. if (enableActiveTab) {
viewModeQueryString = "?view=active-tab&implementation=js";
} else {
viewModeQueryString = "?implementation=js";
}
} elseif (profilerViewMode !== undefined && profilerViewMode !== "full") {
viewModeQueryString = `?view=${profilerViewMode}`;
}
// Find the most recently used window, as the DevTools client could be in a variety // of hosts. // Note that when running from the browser toolbox, there won't be the browser window, // but only the browser toolbox document. const win =
Services.wm.getMostRecentBrowserWindow() ||
Services.wm.getMostRecentWindow("devtools:toolbox"); if (!win) { thrownew Error("No browser window");
}
win.focus();
// The profiler frontend currently doesn't support being loaded in a private // window, because it does some storage writes in IndexedDB. That's why we // force the opening of the tab in a non-private window. This might open a new // non-private window if the only currently opened window is a private window. const contentBrowser = await new Promise(resolveOnContentBrowserCreated =>
win.openWebLinkIn(urlToLoad, "tab", {
forceNonPrivate: true,
resolveOnContentBrowserCreated,
userContextId: win.gBrowser?.contentPrincipal.userContextId,
relatedToCurrent: true,
})
); return contentBrowser;
}
/** *Restartsthebrowserwithagivenenvironmentvariablesettoavalue. * *@param{Record<string,string>}env
*/ function restartBrowserWithEnvironmentVariable(env) { for (const [envName, envValue] of Object.entries(env)) {
Services.env.set(envName, envValue);
}
// Iterate through all tabs in the current window and find the tab that we want. const foundTab = win.gBrowser.tabs.find(
tab => tab.linkedBrowser.browserId === tabId
);
if (!foundTab) {
console.log(`No tab found with the tab id: ${tabId}`); return;
}
// If a matching tab was found, switch to it.
win.gBrowser.selectedTab = foundTab;
// And open the devtools debugger with script. const toolbox = await gDevTools.showToolboxForTab(foundTab, {
toolId: "jsdebugger",
});
toolbox.win.focus();
// In case profiler backend can't retrieve the column number, it can return zero. const columnZeroBased = columnOneBased > 0 ? columnOneBased - 1 : 0;
await toolbox.viewSourceInDebugger(
scriptUrl,
line,
columnZeroBased, /* sourceId = */ null, "ProfilerOpenScript"
);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.