Closed Bug 2059979 Opened 1 month ago Closed 14 days ago

Network monitor opens files in last tab

Categories

(DevTools :: General, defect, P3)

Firefox 153
defect

Tracking

(firefox158 fixed)

RESOLVED FIXED
158 Branch
Tracking Status
firefox158 --- fixed

People

(Reporter: vopros4, Assigned: blessedonekobo, Mentored)

Details

(Whiteboard: [lang=js])

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:153.0) Gecko/20100101 Firefox/153.0

Steps to reproduce:

  1. Open developer tools (F12), switch to the network monitor.
  2. Load any page that loads multiple files, e.g. https://bugzilla.mozilla.org/home
  3. Open several more tabs.
  4. In the tab with open monitor, right-click any file in the monitor, e.g. https://bugzilla.mozilla.org/extensions/BMO/web/images/favicon.svg, "Open in new tab"

Actual results:

A new tab appears on the far right, the link opens there.

The values of browser.tabs.insertAfterCurrent, browser.tabs.insertAfterCurrentExceptPinned and browser.tabs.insertRelatedAfterCurrent do not seem to affect this behaviour.

Expected results:

The expected default behaviour is to open the new tab next to the current one.

The Bugbug bot thinks this bug should belong to the 'Firefox::Tabbed Browser' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Tabbed Browser
Component: Tabbed Browser → General
Product: Firefox → DevTools

For devtools triage: It looks like devtools may be calling gBrowser.addTrustedTab / addWebTab directly: https://searchfox.org/firefox-main/search?q=gBrowser.add&path=devtools&case=true&regexp=false
Utilizing the higher-level URILoadingHelper instead should fix this bug, I think.

Other links (eg Learn More link in console) seem to handle that correctly. Would be nice to fix.

Mentor: nchevobbe
Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Whiteboard: [lang=js]

This is the code for the context menu entry: https://searchfox.org/firefox-main/rev/28b5e86da948982342836c3cca50049659f0dc70/devtools/client/netmonitor/src/widgets/RequestListContextMenu.js#463-468

id: "request-list-context-newtab",
label: L10N.getStr("netmonitor.context.newTab"),
accesskey: L10N.getStr("netmonitor.context.newTab.accesskey"),
visible: !!clickedRequest,
click: () =>
  this.openRequestInTab(id, url, requestHeaders, requestPostData),

which calls https://searchfox.org/firefox-main/rev/28b5e86da948982342836c3cca50049659f0dc70/devtools/client/netmonitor/src/widgets/RequestListContextMenu.js#516-529

/**
 * Opens selected item in a new tab.
 */
async openRequestInTab(id, url, requestHeaders, requestPostData) {
  requestHeaders =
    requestHeaders ||
    (await this.props.connector.requestData(id, "requestHeaders"));

  requestPostData =
    requestPostData ||
    (await this.props.connector.requestData(id, "requestPostData"));

  openRequestInTab(url, requestHeaders, requestPostData);
}

which in turn calls https://searchfox.org/firefox-main/rev/28b5e86da948982342836c3cca50049659f0dc70/devtools/client/netmonitor/src/utils/firefox/open-request-in-tab.js#11-46

/**
 * Opens given request in a new tab.
 */
function openRequestInTab(url, requestHeaders, requestPostData) {
  const win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
  const rawData = requestPostData ? requestPostData.postData : null;
  let postData;

  if (rawData?.text) {
    const stringStream = getInputStreamFromString(rawData.text);
    postData = Cc["@mozilla.org/network/mime-input-stream;1"].createInstance(
      Ci.nsIMIMEInputStream
    );

    const contentTypeHeader = requestHeaders.headers.find(e => {
      return e.name.toLowerCase() === "content-type";
    });

    postData.addHeader(
      "Content-Type",
      contentTypeHeader
        ? contentTypeHeader.value
        : "application/x-www-form-urlencoded"
    );
    postData.setData(stringStream);
  }
  const { userContextId } = win.gBrowser.contentPrincipal;
  win.gBrowser.selectedTab = win.gBrowser.addWebTab(url, {
    // TODO this should be using the original request principal
    triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({
      userContextId,
    }),
    userContextId,
    postData,
  });
}

Other places in DevTools are calling https://searchfox.org/firefox-main/rev/28b5e86da948982342836c3cca50049659f0dc70/devtools/client/shared/link.js#45-70 instead. We should be able ton use this as well, passing the right options

Assignee: nobody → blessedonekobo
Status: NEW → ASSIGNED
Pushed by asilaghi@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/21e13a7a944a https://hg.mozilla.org/integration/autoland/rev/2189cdec42a2 Revert "Bug 2059979 - Fix network monitor opening files in last tab. r=devtools-reviewers,jdescottes" for causing lint failures

Backed out for causing lint failures
Backout Link
Push with failures
Failure Log
Failure line TEST-UNEXPECTED-ERROR | /builds/worker/checkouts/gecko/devtools/client/netmonitor/test/browser_net_open_request_in_tab.js:276:3 | Use dedicated assertion methods (Assert.strictEqual) rather than ok(a === b). (mozilla/no-comparison-or-assignment-inside-ok)

Flags: needinfo?(blessedonekobo)

Sincere apologies. It should be fine now. I didn't get a lint error in my editor. I'll run ./mach lint -w before committing in the future

Flags: needinfo?(blessedonekobo)
Status: ASSIGNED → RESOLVED
Closed: 14 days ago
Resolution: --- → FIXED
Target Milestone: --- → 158 Branch
QA Whiteboard: [qa-triage-done-c159/b158]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: