contentDocument.execCommand gives error in <editor> FF3 RC1 (NS_ERROR_FAILURE)

RESOLVED FIXED in mozilla8



9 years ago
6 years ago


(Reporter: Per-Kristian Nordnes (skogsmaskin), Assigned: Ehsan)



Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)



(3 attachments)



9 years ago
User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; nb-NO; rv:1.9) Gecko/2008051202 Firefox/3.0
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; nb-NO; rv:1.9) Gecko/2008051202 Firefox/3.0

I'm updating my extension for Firefox 3, and I have a XUL editor, where 
xulEditor.contentDocument.queryCommandState('bold') now fails and gives the following error:

Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMNSHTMLDocument.queryCommandState]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"

Worked fine in Firefox 2. Can't seem to get around this. Any ideas?

Reproducible: Always

Steps to Reproduce:
1. Set up a XUL editor field in chrome.
2. Try to query the commandstate within the editing document using xulEditor.contentDocument.queryCommandState('bold')
Component: General → Editor
Product: Firefox → Core
QA Contact: general → editor

Comment 1

9 years ago
Created attachment 322137 [details]
A test XUL file. Please put it in chrome.


9 years ago
Severity: normal → critical


9 years ago
Summary: queryCommandState crashes in regard to XUL editor (NS_ERROR_FAILURE) → contentDocument.queryCommandState and execCommand crashes in regard to XUL editor in chrome (NS_ERROR_FAILURE)
I can confirm that this worked in 1.9b2pre, but does not work in latest 1.9pre
Ever confirmed: true
Per-Kristian - a narrowed regress range would be helpful. See if you can find the Firefox nightly that started throwing exceptions.

Comment 4

9 years ago
Thank you for the confirmation mfinkle, I'll see if I can find it.
Summary: contentDocument.queryCommandState and execCommand crashes in regard to XUL editor in chrome (NS_ERROR_FAILURE) → contentDocument.execCommand gives error in FF3 RC1 (NS_ERROR_FAILURE)

Comment 5

9 years ago
It happened in

Comment 6

9 years ago
mfinkle found out that <browser> doesn't have these problems, so a temporary workaround is to user browser instead of editor. Then in order to get <editor> stuff:

var myBrowser = document.getElementById('myBrowser');
var editingSession = myBrowser.webNavigation.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIEditingSession);
myBrowser.contentDocument.designMode = 'on';
var editor = editingSession.getEditorForWindow(myBrowser.contentWindow);
var commandManager = myBrowser.webNavigation.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsICommandManager);
var htmlEditor = editor.QueryInterface(Components.interfaces.nsIHTMLEditor);

Works for now, until this bug is fixed.
Summary: contentDocument.execCommand gives error in FF3 RC1 (NS_ERROR_FAILURE) → contentDocument.execCommand gives error in <editor> FF3 RC1 (NS_ERROR_FAILURE)
For some reason the mEditingState is set to eOff when checked here:

I'm not sure why yet.
Maybe this was caused by Bug 428844, which was checked in on 2008-04-17? That changed how we tore down the editor. The old editor is tore down before the new one is setup, maybe that's failing...
mEditingState is eOff because SetDesignMode considers setting designMode='on' to be redundant for a document that is already editable, see Fixing this will probably require quite a bit of changes.

What does using an editor element with designMode="on" give that a simple editor element or a browser element with designMode="on" doesn't? Unless there's an important advantage I don't think this is a high priority bug.

Comment 10

9 years ago
It has property commandManager, and methods getHTMLEditor and getEditor for instance.

But the critical point is that the editor element simply doesn't work for what it is designed for, to edit stuff. So all extensions and such using a <editor> will not work, and break stuff when it comes down to executing commands like bold, italic, link, etc. I can't see how that can not be critical?
Executing commands like cmd_bold, ... with the commandManager is broken?
Created attachment 322786 [details]
Testcase using commandManager

Using the commandManager works fine for me?

Comment 13

9 years ago
Using commandManager like that works here too. But not contentDocument.execCommand (and similar calls) as it did before 2004-04-18.

Quote from

Once editable, the document can have special formatting and other HTML pieces added to it using the document.execCommand method:

    var editor = document.getElementById("myEditor");

    // toggle bold for the current selection
    editor.contentDocument.execCommand("bold", false, null);

I suppse it's not only my code that will suffer from this bug.

Comment 14

9 years ago
I have a similar problem in FF3 when trying to use execCommand on an iframe editor see This bug did not exist in FF1 or 2 and works in other browsers.

Comment 15

9 years ago
Same error with Fx 3.1 on linux. 
But I have fixed the problem by adding contenteditable="true" in a HTML element of the content document.
Duplicate of this bug: 671248
Created attachment 546023 [details] [diff] [review]
Patch (v1)

For <xul:editor>, the HTML document's mEditingState ended up being eOff, which effectively disables the execCommand API.  This patch is a simple fix for that.
Assignee: nobody → ehsan
Attachment #546023 - Flags: review?(roc)
Comment on attachment 546023 [details] [diff] [review]
Patch (v1)

Review of attachment 546023 [details] [diff] [review]:
Attachment #546023 - Flags: review?(roc) → review+
Last Resolved: 6 years ago
Flags: in-testsuite+
Keywords: dev-doc-needed
OS: Mac OS X → All
Hardware: PowerPC → All
Resolution: --- → FIXED
Target Milestone: --- → mozilla8
Version: unspecified → Trunk

Comment 20

6 years ago
Try run for fe3b8f619f5c is complete.
Detailed breakdown of the results available here:
    success: 148
    warnings: 13
    failure: 2
Total buildrequests: 163
This bug fix is noted here:
Keywords: dev-doc-needed → dev-doc-complete
You need to log in before you can comment on or make changes to this bug.