Closed Bug 1797947 Opened 2 years ago Closed 1 year ago

Opening DevTools triggers PerformanceObserver (with entryTypes: ["resource"]) callback

Categories

(DevTools :: Inspector, defect)

Firefox 106
defect

Tracking

(firefox109 verified, firefox110 verified)

VERIFIED FIXED
109 Branch
Tracking Status
firefox109 --- verified
firefox110 --- verified

People

(Reporter: bzugmeyer, Assigned: sefeng)

References

()

Details

Attachments

(2 files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0

Steps to reproduce:

  1. Navigate to https://firefox-duplicated-performancetiming-for-css.benoitzugmeyer.repl.co/ or any page with a few stylesheets included via <link> tags

  2. Open the devtools Inspector panel (ex: right click > Inspect element)

  3. Many PerformanceTiming entries are reported to PerformanceObserver callbacks with their .name property referencing stylesheets URLs multiple times. In the demo page above, many ENTRY lines are showing up for the two stylesheets, even if the stylesheets are downloaded only once.

I tried a few anterior Firefox versions and the issue occurs way more since Firefox 89. Before that, PerformanceTiming entries were still repeated but just a few times.

Actual results:

Many PerformanceTiming are reported for stylesheets even if they are requested only once

Expected results:

Only one PerformanceTiming is reported for each requested stylesheet.

Comment on attachment 9300736 [details]
Screenshot 2022-10-28 at 11.56.05.png

Screenshot showing the issue on https://firefox-duplicated-performancetiming-for-css.benoitzugmeyer.repl.co/ on Firefox 106. As we can see, PerformanceTiming entries are repeated many times.

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

Component: Untriaged → Inspector
Product: Firefox → DevTools

Thanks for the report Benoît.
I think we got a similar bug recently as DevTools are fetching resources from the network, but I can't find it at the moment.

Summary: Duplicated resource PerformanceTiming entries when opening the Devtools → Opening DevTools triggers PerformanceObserver (with entryTypes: ["resource"]) callback

Using cacheKey doesn't seem to help here.

As mentioned in comment #5 we use both the window and principal options for this fetch call. The PerformanceObserver seems triggered as long as we set the window option. But using the same window as the page is still required for Bug 1405342.

So on one hand we want to request the stylesheet as if it was requested from the actual page, but we still would like to have a way to hide it from the PerformanceObserver. Markus, do you know if there is anything we could do to hide the fetch call at https://searchfox.org/mozilla-central/rev/73ff5f1ac45202c4621a1bcee4b35d20027e71ad/devtools/server/actors/utils/stylesheets-manager.js#457 from the PerformanceObserver

Flags: needinfo?(jdescottes) → needinfo?(mstange.moz)

I don't know the PerformanceObserver code all that well, forwarding to Sean.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(mstange.moz) → needinfo?(sefeng)
OS: Unspecified → All
Hardware: Unspecified → All

I don't think we could do this from the javascript side, however I think we can utilize IsInDevToolsContext to filter these fetch requests out. Though I am not sure if it'll break existing PerformanceObserver usage in the devtools (if we have some), probably need to check IsInDevToolsContext + content principal I think.

I'll write a write a patch for this next week.

Devtools can generate fetch request on behalf of the content document,
reporting these requests in PerformanceObserver would cause confusion,
so we should ignore them.

Assignee: nobody → sefeng
Status: NEW → ASSIGNED
Attachment #9304494 - Attachment description: Bug 1797947 - Make devtools generated fetch request exclude from resource timing r=jdescottes,valentin → Bug 1797947 - Make devtools generated fetch requests excluded from resource timing r=jdescottes,valentin

I wrote the patch, so removing my NI.

Flags: needinfo?(sefeng)
Pushed by sefeng@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/b3760215fcc0
Make devtools generated fetch requests excluded from resource timing r=jdescottes,valentin,necko-reviewers
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 109 Branch
QA Whiteboard: [qa-109b-p2]

Reproducible on a 2022-10-28 Nightly build on macOS 12.
Verified as fixed on Firefox 109.0b6(build ID: 20221222190305) and Nightly 110.0a1(build ID: 20221226154927) on macOS 12, Windows 10, Ubuntu 22.

Status: RESOLVED → VERIFIED
QA Whiteboard: [qa-109b-p2]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: