Closed Bug 1615305 Opened 5 years ago Closed 5 years ago

Show lazy load as Cause for requests

Categories

(DevTools :: Netmonitor, enhancement, P3)

enhancement

Tracking

(firefox77 fixed)

RESOLVED FIXED
Firefox 77
Tracking Status
firefox77 --- fixed

People

(Reporter: Harald, Assigned: hiro)

References

(Blocks 1 open bug)

Details

Attachments

(2 files, 1 obsolete file)

The cause column should show lazy as the primary cause or add (lazy) as sub-cause if we want to keep both fields around.

This needs to be exposed by platform: https://searchfox.org/mozilla-central/source/devtools/server/actors/network-monitor/network-observer.js#680

Lazy does not seem to add a new content policy (vs preload): https://searchfox.org/mozilla-central/source/dom/base/nsContentUtils.h#3398 , so maybe we need a different way to tell the network observer.

Hiro offered to look into how lazy load can be exposed as cause for requests.

Flags: needinfo?(hikezoe.birchill)

One important thing I should note is that lazy-loading doesn't trigger any network requests during the image is out-of-view. So we need to send a new notification to devtools in HTMLImageElement::SetLazyLoading when the image gets in the state waiting for being visible (i.e. lazy-load) and maybe send another notification in HTMLImageelement::StopLazyLoadingAndStartLoadIfNeeded when the image is no longer lazy-loading state. I don't think the latter is necessary because once after the image became non-lazy state, the image will be loaded thus a new network request appears.

I am not sure about the actually way to send the notifications, probably need to ask someone familiar with network or DOM.

Harald, is this sufficient for you guys?

Flags: needinfo?(hikezoe.birchill) → needinfo?(hkirschner)

I just realized in the network panel there is a column to show the filename of the image (I guess it's picked from src attribute), and the filename can be changed during lazy-loading state. So I am not quite sure what we should do for users in such cases, and for the notification we need to send a notification that src attribute is changed too.

(In reply to Hiroyuki Ikezoe (:hiro) from comment #3)

One important thing I should note is that lazy-loading doesn't trigger any network requests during the image is out-of-view. So we need to send a new notification to devtools in HTMLImageElement::SetLazyLoading when the image gets in the state waiting for being visible (i.e. lazy-load) and maybe send another notification in HTMLImageelement::StopLazyLoadingAndStartLoadIfNeeded when the image is no longer lazy-loading state. I don't think the latter is necessary because once after the image became non-lazy state, the image will be loaded thus a new network request appears.

If I understand the feature suggestion correctly - the Network panel should indicate when an HTTP requests (e.g. for images) where caused by lazy loading strategy (e.g. img element using loading="lazy"). In such case we'll just display "lazy" (or similar label) for such requests.

This means that the net panel isn't that much interested in set of images that are supposed to be lazy loaded - rather in a flag that says that actual HTTP request for image has triggered due to lazy loading technique (e.g. channel.loadInfo.lazyLoad == true)

@Harald, is that accurate?

I am not sure about the actually way to send the notifications, probably need to ask someone familiar with network or DOM.

The network panel is usually consuming notifications through nsIObserverService
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIObserverService

e.g. http-on-modify-request, http-on-opening-request, etc.
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Observer_Notifications

But, not sure whether we need a new notification, I am rather expecting a flag ...

(In reply to Hiroyuki Ikezoe (:hiro) from comment #4)

I just realized in the network panel there is a column to show the filename of the image (I guess it's picked from src attribute), and the filename can be changed during lazy-loading state. So I am not quite sure what we should do for users in such cases, and for the notification we need to send a notification that src attribute is changed too.

The Network panel is not using DOM elements, it's solely consuming Necko events about HTTP requests so, the name is URL from nsIChannel (HTTP request)

Honza

@Harald, is that accurate?

Yes. We already have a cause field that we would probably use for that.

Flags: needinfo?(hkirschner)

Is this something your team can help with or should we look to other teams, like Necko?

Flags: needinfo?(hikezoe.birchill)

I was totally misunderstanding what we need in the network panel. I didn't even know there is Cause column. :/

So, if I understand correctly we just want to show a different string in the Cause column? If the corresponding image data hasn't started loading, we don't need to show anything right?

Then, it's pretty easy to tell whether the corresponding image is lazy-loading or not, we just need to check the channel.loadFlags.

Here is a patch to append lazy- prefix string for lazy loading image. I hope this can help you guys what we have to do in devtools.

Flags: needinfo?(hikezoe.birchill)
Attached image image.png

Hiro, this is great, thanks for the update!

Harald, this looks nice&simple, should we polish the label (e.g. show rather img (lazy)) and land?
I am attaching a screenshot.

Honza

Flags: needinfo?(hkirschner)

Thank you for the screenshot. Let's land this as is and revisit when we have other fields like preload. Lazy loading only applies to images, so this works well as is.

Flags: needinfo?(hkirschner)

Honza, do you what's needed to land this?

Flags: needinfo?(odvarko)

Hiro, can you please uplift the attached patch to Phab and ask me for review, please?
It works just fine and we can land it.

Please let me know even if you don't have time to work on this, I can find someone else to land it.

Thanks!
Honza

Flags: needinfo?(odvarko) → needinfo?(hikezoe.birchill)
Assignee: nobody → hikezoe.birchill
Status: NEW → ASSIGNED
Flags: needinfo?(hikezoe.birchill)

I didn't notice that html_cause-test-page.html I touched is also used for browser_net_initiator.js test.
https://treeherder.mozilla.org/#/jobs?repo=try&revision=8d06b5b41b6e53b447c32a9ca80b1c71515b3e78

Thanks Hiro, this is great help!

The patch is R+ but, let's land it after 77 merge (next week Tuesday)

Honza

Flags: needinfo?(odvarko)
Pushed by hikezoe.birchill@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/bcff183d3130 Add `lazy-` prefix for lazy-loading images. r=Honza
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 77
See Also: → 1628423
Flags: needinfo?(odvarko)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: