Closed Bug 1783021 Opened 2 years ago Closed 2 years ago

Tab crashes caused by extension "ContextSearch web-ext"'s Quick Menu after Inspector's Animations View has been activated once

Categories

(Core :: DOM: Animation, defect, P3)

defect

Tracking

()

RESOLVED FIXED
107 Branch
Tracking Status
firefox-esr102 --- wontfix
firefox105 --- wontfix
firefox106 --- wontfix
firefox107 --- fixed

People

(Reporter: Fanolian+BMO, Assigned: hiro)

References

Details

(Keywords: crash, regression, reproducible)

Crash Data

Attachments

(3 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0
Build ID: 20220803094413

Steps to reproduce

  1. In a new profile, install ContextSearch web-ext 1.41.1. Keep extension's settings as default.
  2. Open any webpage, e.g. https://www.example.com/.
  3. Open Firefox's Inspector. Switch the right-pane to Animations.
  4. Invoke ContextSearch's Quick Menu by:
    4a. highlighting a word; and then
    4b. holding a right-click.
  5. Dismiss Quick Menu by left-clicking anywhere outside Quick Menu.

Actual result

The tab crashes with signature [@ mozilla::dom::MutationObservers::NotifyAnimationMutated ].

Expected result

No crashes.

Additional notes

  1. A crash can be triggered even if Animation View is not active, as long as it has been activated at least once after a page is loaded. I.E. (Step 1 is implied):
    a: step 2 > 3 > switch to Layout View / close Inspector > step 4 > 5 => Crash;
    b: step 2 > 3 > keep Animations View active > reload page > 4 > 5 => Crash;
    c: step 2 > 3 > switch to Layout View / close Inspector > reload page > 4 > 5 => NO Crashes;
    d: open a new tab (about:newtab) > step 3 > 2 > 4 > 5 => Crash.

  2. This crash is a longstanding bug. I can reproduce it since 2020-05-13 build but only because ContextSearch's Quick Menu stopped working/cannot be invoked prior to that build.

  3. ContextSearch's Quick Menu works most of the time besides this scenario.

Crash Signature: [@ mozilla::dom::MutationObservers::NotifyAnimationMutated ] → [@ mozilla::dom::MutationObservers::NotifyAnimationMutated]
Has STR: --- → yes
Keywords: reproducible

:Fanolian+BMO, if you think that's a regression, could you try to find a regression range using for example mozregression?

ContextSearch web-ext's author is notified via https://github.com/ssborbis/ContextSearch-web-ext/issues/524.

The crash happens since ContextSearch v1.40rc3 which can be found in its github page.

The attached video shows that with v1.40rc3+, Animation View cannot show the animation details and results a crash.

Although the crash is caused by a change of an extension, Firefox should not crash anyway. I am leaving this bug report open.

I've narrowed down the cause to removing an element from the shadowDOM before a CSS transition completes. After opening the Inspector window to the Animations tab, the following code should crash a tab relatively consistently.

(() => {
  let s = document.createElement('shadow-test');
  document.documentElement.appendChild(s);
  s.attachShadow({mode:"open"});
  
  let property = 'opacity';
  let initial = '1';
  let final = '0';
  
  let div = document.createElement('div');
  div.style = `${property}:${initial};transition:${property} 2s;`

  s.shadowRoot.appendChild(div);
  div.offsetWidth;

  div.style[property] = final;
  setTimeout(() => div.parentNode.removeChild(div), 1000);
})();

The bug has a crash signature, thus the bug will be considered confirmed.

Status: UNCONFIRMED → NEW
Ever confirmed: true

The crash seems to be triggered as soon as we start observing mutations with animations set to true, which is what the animations actor does at https://searchfox.org/mozilla-central/rev/14781effaa15c12b1652beb75f021489567bad8f/devtools/server/actors/animation.js#665-669

Meaning this can be reproduced without the Animation Inspector, by executing the following snippet in chrome scope of a content process:

  let observer = new tabs[0].content.MutationObserver(() => {});
  observer.observe(tabs[0].content.document.documentElement , {
    animations: true,
    subtree: true,
  }); 

And then run the snippet from comment 5 in the tab where you started the observer.

Component: Inspector: Animations → DOM: Core & HTML
Product: DevTools → Core

This looks similar (or duplicate of) to bug 1669165.

Component: DOM: Core & HTML → DOM: Animation

The severity field is not set for this bug.
:boris, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(boris.chiou)

Thanks for the initial investigation. I will take a look later.

Severity: -- → S3
Flags: needinfo?(boris.chiou)
Priority: -- → P3

I looked this a bit since a relevant bug (bug 1669165) is in our S2 list.

All the crashes here were triggered one of these RemoveProperty calls in Element::UnbindFromTree. An important fact here is that these RemoveProperly calls are invoked after we unset mParent in the same function. And in the MutationObservers::NotifyAnimationMutated function, we end up calling ShadowRoot::FromNode which invokes nsINode::IsShadowRoot and in the function we have;

const bool isShadowRoot = IsInShadowTree() && !GetParentNode();

The GetParentNode() is now totally wrong since mParent has been already nullified.

Just moving up those RemoveProperty calls before nullifying mParent would resolve this issue.

Without this change we can't tell properly whether the element in question is the
shadow root or not in animation mutation observer, specifically at a
ShadowRoot::FromNote call in ForEachAncestorObserver [1].

The test case in this change is based on a test case created by Julian Descottes [2].

[1] https://searchfox.org/mozilla-central/rev/b1e5f2c7c96be36974262551978d54f457db2cae/dom/base/MutationObservers.cpp#67
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1783021#c9

Assignee: nobody → hikezoe.birchill
Status: NEW → ASSIGNED

Thanks you Julian for the test case in comment 9! It was quite easy to write a mochitest based on the test case.

Pushed by hikezoe.birchill@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1214807cfb19 Remove animation related properties before nulling out nsINode::mParent. r=smaug,jdescottes

The test, test_animation_observers_sync.html caused a bunch of assertion "ASSERTION: shouldn't have observed an animation being removed", this is a variant of bug 1189015.

With the change for this bug, in ForEachAncestorObserver we properly walk up DOM tree node here so that if a MutationObserver observe the parent element of the animated element, thus AnimationAdded gets called twice, one is for the animated element, the other one is the parent element.

I am not sure what the proper fix for bug 1189015, I am just going to allow the assertions in the test. For that, we need bug 1792514.

Depends on: 1792514
Flags: needinfo?(hikezoe.birchill)
See Also: → 1189015
Pushed by hikezoe.birchill@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7b3bd80aa22b Remove animation related properties before nulling out nsINode::mParent. r=smaug,jdescottes
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 107 Branch

The patch landed in nightly and beta is affected.
:hiro, is this bug important enough to require an uplift?

  • If yes, please nominate the patch for beta approval.
  • If no, please set status-firefox106 to wontfix.

For more information, please visit auto_nag documentation.

Flags: needinfo?(hikezoe.birchill)
Flags: needinfo?(hikezoe.birchill)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: