0
votes

I'm developing a Firefox extension using Firefox addon-sdk. One of my content scripts is trying to insert some text into an editable div by using this standard javascript function:

document.execCommand("InsertHTML", false, 'test text');

The above code works perfectly in my Chrome extension but fails in Firefox with this error:

[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHTMLDocument.execCommand]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" data: no]

Is there any other solution to insert text at the current position into an editable div(in a content script).

Thanks in advance

1
The code you show above works just fine in Firefox for me. Can you link to a page that doesn't work for you?Boris Zbarsky
@BorisZbarsky it works in a simple html in firefox, but not in my firefox add-on's content scriptKirill Ivlev
OK, can you link to a content script that shows the problem? Does running something similar to what you're doing in GreaseMonkey work?Boris Zbarsky

1 Answers

0
votes

In my first glance, the function doesn't exist, resp. is not accessible:

Either due to NOT making the WHOLE doc editable (at least FF 3.5.13 shows that behaveiour) resp. 'midas' not invoked OR a timing problem: the invoke of midas may take some (100?) millisec. In the case editability is triggerd by script or otherwise after load of page, one should await the 'appearence' of the function (of the DOCUMENT).execCommand as midas load-completion succeeds.