Closed Bug 1901765 Opened 1 year ago Closed 1 year ago

Error when using "Copy Rule" context menu entry when there's no rule at cursor position

Categories

(DevTools :: Inspector: Rules, defect, P3)

defect

Tracking

(firefox129 verified, firefox130 verified)

VERIFIED FIXED
129 Branch
Tracking Status
firefox129 --- verified
firefox130 --- verified

People

(Reporter: nchevobbe, Assigned: nchevobbe)

Details

Attachments

(1 file)

Alex noticed he could easily get errors when copying rules:

while testing copying rules, I found that you can easily get a resource://devtools/client/inspector/shared/style-inspector-menu.js, line 474: TypeError: can't access property "stringifyRule", rule is null exception and a test as simple as data:text/html,foo.
But the exception doesn't seem to break anything.

Alex, I wasn't able to reproduce the issue, how are you copying the rule? both selecting with the mouse and doing Cmd+C, or using the context menu entry don't trigger the error you reported on my machine

Flags: needinfo?(poirot.alex)

My STR is the following:

  • open data:text/html,foo
  • open inspector (<body> is selected by default)
  • right click anywhere in the rule view and click on Copy Rule

I'm getting JavaScript error: resource://devtools/client/inspector/shared/style-inspector-menu.js, line 474: TypeError: can't access property "stringifyRule", rule is null printed in stdout.

Flags: needinfo?(poirot.alex)

Thanks for the STR, I can reproduce easily now
We probably shouldn't display the context menu entry if there's no rule behind the cursor.
The check that we do to display the entry is simply "are we in the rule view", which is a bit naive

https://searchfox.org/mozilla-central/rev/4582d908c17fbf7924f5699609fe4a12c28ddc4a/devtools/client/inspector/shared/style-inspector-menu.js#115-121

const menuitemCopyRule = new MenuItem({
  label: STYLE_INSPECTOR_L10N.getStr("styleinspector.contextmenu.copyRule"),
  click: () => {
    this._onCopyRule();
  },
  visible: this.isRuleView,
});
Severity: -- → S3
Priority: -- → P3
Summary: Error when copying rule → Error when using "Copy Rule" context menu entry when there's no rule at cursor position
Assignee: nobody → nchevobbe
Status: NEW → ASSIGNED
Pushed by sstanca@mozilla.com: https://hg.mozilla.org/mozilla-central/rev/f81fd085df11 [devtools] Don't display Copy Rule in context menu when there's no rule for the target. r=devtools-reviewers,ochameau.
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 129 Branch

Reproducible on a 2024-06-11 Nightly build on Windows 10.
Verified as fixed on Firefox 129.0b2 and Firefox Nightly 130.0a1 on Windows 10, macOS 14, Ubuntu 22.

Status: RESOLVED → VERIFIED
Flags: qe-verify+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: