Hey PH, mind taking a look at this when you have the chance, before I add upstream reviewers?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
if (RuntimeEnabledFeatures::LazyLoadVideoAndAudioEnabled() &&nit: The `InsertedInto` method above checks `insertion_point.isConnected()` before the call to `StartMonitoring`. Even though `StartMonitoring` and `StopMonitoring` check for document validity with `GetRootDocumentOrNull`, should the conditional here mirror what `InsertedInto` does and also call `insertion_point.isConnected()`?
EXPECT_GT(observer.GetObservationCountForTesting(), 0u);nit: since there should only be 1 observer (please correct me if I'm wrong), could this check be tightened to the following to catch any other related bugs?
```suggestion
EXPECT_EQ(observer.GetObservationCountForTesting(), 1u);
```
}nit: You mentioned in the comment above that "If the element is re-inserted, InsertedInto() will restart monitoring.". Would it be beneficial to re-insert the element to make sure this statement is correct? Perhaps something like:
```suggestion
GetDocument().body()->AppendChild(video);
EXPECT_EQ(observer.GetObservationCountForTesting(), 1u);
}
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
if (RuntimeEnabledFeatures::LazyLoadVideoAndAudioEnabled() &&nit: The `InsertedInto` method above checks `insertion_point.isConnected()` before the call to `StartMonitoring`. Even though `StartMonitoring` and `StopMonitoring` check for document validity with `GetRootDocumentOrNull`, should the conditional here mirror what `InsertedInto` does and also call `insertion_point.isConnected()`?
I took a look, seems like `isConnected()` could be either `true` (direct removal) or `false` (subtree removal, e.g. removing a `<div>` that contains the video). We want to stop monitoring here either way, so I don't think we want the check here.
EXPECT_GT(observer.GetObservationCountForTesting(), 0u);nit: since there should only be 1 observer (please correct me if I'm wrong), could this check be tightened to the following to catch any other related bugs?
```suggestion
EXPECT_EQ(observer.GetObservationCountForTesting(), 1u);
```
Done
nit: You mentioned in the comment above that "If the element is re-inserted, InsertedInto() will restart monitoring.". Would it be beneficial to re-insert the element to make sure this statement is correct? Perhaps something like:
```suggestion
GetDocument().body()->AppendChild(video);
EXPECT_EQ(observer.GetObservationCountForTesting(), 1u);
}
```
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Hi Dale and Helmut, adding the two of you because you were on the original crbug for HTML video element lazy-loading. Please take a look when you have a chance, thanks!
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
Hi Dale and Helmut, adding the two of you because you were on the original crbug for HTML video element lazy-loading. Please take a look when you have a chance, thanks!
Thanks! This looks right to me, but please let Helmut weigh in.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
awesome! looking good thanks for looping me in, and thanks for fixing the bug!
// InsertedInto() will restart monitoring.optional nit: i'd remove this comment
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
| Commit-Queue | +1 |
optional nit: i'd remove this comment
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Dale CurtisHi Dale and Helmut, adding the two of you because you were on the original crbug for HTML video element lazy-loading. Please take a look when you have a chance, thanks!
Thanks! This looks right to me, but please let Helmut weigh in.
Done
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
| Commit-Queue | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Fix stale observation crash in LazyLoadMediaObserver on media element removal
The LazyLoadVideoAndAudio feature (crbug.com/469111735) added media
elements to LazyLoadMediaObserver but did not add cleanup in
HTMLMediaElement::RemovedFrom. When a <video loading="lazy"> element
is removed from the DOM, its IntersectionObservation remains in the
observer. If garbage collection later collects the element while the
observation is held alive by active_observations_, a subsequent call
to LoadAllImagesAndBlockLoadEvent (e.g. via print preview) can
dereference the null target, causing an ACCESS_VIOLATION crash.
This crash is non-deterministic, depending on GC timing relative to
intersection computation and notification delivery.
This CL:
- Calls LazyMediaHelper::StopMonitoring in
HTMLMediaElement::RemovedFrom when the element is in the deferred
lazy-load state, matching the cleanup that ImageLoader already does
for images.
- Adds a regression test verifying that the observation is cleaned up
after removal.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |