Closed Bug 1274877 Opened 8 years ago Closed 8 years ago

contextMenus API starts logging errors after removing an item

Categories

(WebExtensions :: Untriaged, defect, P1)

defect

Tracking

(firefox48 affected, firefox49 affected, firefox50 verified)

VERIFIED FIXED
mozilla50
Iteration:
50.1 - Jun 20
Tracking Status
firefox48 --- affected
firefox49 --- affected
firefox50 --- verified

People

(Reporter: wbamberg, Assigned: bsilverberg)

References

Details

(Whiteboard: [context menu] triaged)

Attachments

(2 files)

Attached file context-menu.zip
Here's a WebExtension, that creates a context menu item labeled "Remove me!". If you click the item, it is removed.

After this, if you open the context menu, the item no longer appears, but an error is logged to the console:

TypeError: rootElement.firstChild is null   ext-contextMenus.js:43:11
Priority: -- → P1
Whiteboard: [context menu] triaged
I'll take this for now as it's a P1 and unassigned. I think Matt is our resident contextMenus expert, but he's on PTO.
Assignee: nobody → bob.silverberg
Status: NEW → ASSIGNED
Iteration: --- → 50.1
The problem occurs if you add contextMenu items and then remove all of them. I am attaching a fix.
https://reviewboard.mozilla.org/r/58292/#review55154

::: browser/components/extensions/test/browser/browser_ext_contextMenus.js:398
(Diff revision 1)
>    yield extension.unload();
>  
>    yield BrowserTestUtils.removeTab(tab1);
>  });
> +
> +add_task(function* test_remove_only_item() {

Note that this test can be run to reproduce the error without the patch to `ext-contextMenus.js`. Unfortunately, the only manifestation of the bug is an error message to the JavaScript console, and I'm not sure how to check for that (or rather, the absence of that) in the test, so right now this test does not disprove the bug.
If there are multiple extensions with context menus, and one of them produces this error, it will also break the extensions that come after it.

So we should try testing this with two active extensions.
(In reply to Kris Maglione [:kmag] from comment #5)
> If there are multiple extensions with context menus, and one of them
> produces this error, it will also break the extensions that come after it.
> 
> So we should try testing this with two active extensions.

Do you mean manually, or in an automated test. Can we load two extensions in a test?
(In reply to Bob Silverberg [:bsilverberg] from comment #6)
> Do you mean manually, or in an automated test.

Automated, but it might be worth trying to reproduce it manually as well.

> Can we load two extensions in a test?

Yes, but not easily. If you want to file a bug to add a utility for that, and
a follow-up bug to add tests for this that depends on it, this is probably
good to land. We should also request uplift, if you can verify the breakage
with multiple extensions installed.
(In reply to Kris Maglione [:kmag] from comment #7)
> (In reply to Bob Silverberg [:bsilverberg] from comment #6)
> > Do you mean manually, or in an automated test.
> 
> Automated, but it might be worth trying to reproduce it manually as well.
> 
> > Can we load two extensions in a test?
> 
> Yes, but not easily. If you want to file a bug to add a utility for that, and
> a follow-up bug to add tests for this that depends on it, this is probably
> good to land. We should also request uplift, if you can verify the breakage
> with multiple extensions installed.

I have manually verified that it does break contextMenus for other extensions that are installed. For landing this, I assume I should remove the current test that doesn't actually prove anything, so that all we'll land right now is the fix. Agreed?
Blocks: 1278685
Comment on attachment 8760883 [details]
Bug 1274877 - contextMenus API starts logging errors after removing an item,

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/58292/diff/1-2/
Attachment #8760883 - Flags: review?(bob.silverberg)
(In reply to Bob Silverberg [:bsilverberg] from comment #8)
> For landing this, I assume I should remove the current test that doesn't
> actually prove anything, so that all we'll land right now is the fix.
> Agreed?

Yes.
Comment on attachment 8760883 [details]
Bug 1274877 - contextMenus API starts logging errors after removing an item,

https://reviewboard.mozilla.org/r/58292/#review55256
Attachment #8760883 - Flags: review?(kmaglione+bmo) → review+
Attachment #8760883 - Flags: review?(bob.silverberg)
Keywords: checkin-needed
Vasilica, we're going to want this uplifted to 48 and 49, so could you please verify this fix. Without the patch, if you have two extensions each of which add to the contextMenu, and one of them removes all of the items it created from the contextMenu, the contextMenu items for the other extension should stop showing up as well. You'll also notice the error mentioned in the initial description in the JavaScript console after removing all of the items, without the patch.
Flags: needinfo?(vasilica.mihasca)
Keywords: qawanted
I was able to reproduce this issue on Firefox 50.0a1 (2016-06-08), Firefox 49.0a2 (2016-06-07) and Firefox 48.0a2 (2016-06-06) under Windows 10 64-bit and Ubuntu 14.04 32-bit.

Tested using https://treeherder.mozilla.org/#/jobs?repo=try&revision=60f38abe350c&selectedJob=22155083
Under Windows 10 64-bit and it seems to be fixed. The contextMenu item for the other webextension remains displayed after clicking on “Remove me!” and there is no javascript error thrown in Browser Console.
Flags: needinfo?(vasilica.mihasca)
Keywords: qawanted
OS: Unspecified → All
Hardware: Unspecified → All
Version: unspecified → Trunk
Pushed by kcambridge@mozilla.com:
https://hg.mozilla.org/integration/fx-team/rev/aaac9952244e
contextMenus API starts logging errors after removing an item, r=kmag
Keywords: checkin-needed
Thanks Vasilica!
https://hg.mozilla.org/mozilla-central/rev/aaac9952244e
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla50
I was able to reproduce the initial issue on Firefox 49.0a1 (2016-05-20) under Windows 10 64-bit.

Verified fixed on Firefox 50.0a1 (2016-07-31) under Windows 10 64-bit and Ubuntu 14.04 32-bit. The error is no longer thrown in Browser Console.
Status: RESOLVED → VERIFIED
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: