I am getting an error when there are 2 or more instances of the CKEditor in a single page.
I get Uncaught TypeError: Cannot call method 'getFrameDocument' of null in the line ckeditor.js line 102.
After this the counter plugin stops working as well..

CommentFileSizeAuthor
#18 ckeditor.counter.patch604 bytesAlice Heaton
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

inian’s picture

Priority: Major » Critical
dczepierga’s picture

Priority: Critical » Normal

Could u write which module u're using to have more instances of CKEditor in a single page?

When u disable this plugin everything works fine?

Greetings

dczepierga’s picture

Status: Active » Postponed (maintainer needs more info)
inian’s picture

I have written a custom module where I am having multiple instances of the ckeditor.
If I disable this plugin, everything is working normally.

dczepierga’s picture

It is possible to send me this module? It will help me to reproduce this and fix it asap...

Greetings

inian’s picture

To reproduce the error on a fresh Drupal install,
Attach a field to a content type which has ckeditor and set the 'number of values' to unlimited.
Make sure that the word count plugin is enabled.
When u click on the 'add another item' button and new instances of ckeditor are getting added, the "Uncaught TypeError: Cannot call method 'getFrameDocument' of null " exception occurs. (it usually occurs when I click on the "add new item" button twice and there are 3 instances of ckeditor on the screen. The error occurs immediately when i click on the third ckeditor)
After this the counter plugin stops working entirely.

PS - I have uncommented the editor.on( 'key', count); in the counter plugin so that the word count keeps updating as the user types.

inian’s picture

Status: Postponed (maintainer needs more info) » Active
dczepierga’s picture

@inian, if u disable count symbols on every key u still get this error?
Which browser do u use to check this?

Greetings

dczepierga’s picture

Status: Active » Postponed (maintainer needs more info)
inian’s picture

@dczepierga
Yes the error occurs even when the count on every key is disabled.
I checked this in chrome.

dczepierga’s picture

I check this with Chrome 19 and Firefox 12 - for me works when every key is disabled. If i enable this option a have some errors after few seconds of using...

Do u don't use any custom theme or page cache/optimize?
Do u try to use last DEV version of CKEditor module with last CKEditor library?

Greetings

inian’s picture

I checked the issue again with Chrome 19, fresh Drupal install and after disabling the updating process when every key is pressed. I also used the latest CKeditor library and the latest development release Druapl ckeditor module for testing.
I had to add around 5 CKeditors to a single page for me to get the error when every key press is disabled. When it is enabled, I get the error even when there are 3 ckeditors in the page..

inian’s picture

This is the entire stacktrace of the error :-
Uncaught TypeError: Cannot call method 'getFrameDocument' of null ckeditor.js:102
j.add.init.C.on.C.addMode.getData ckeditor.js:102
(anonymous function) ckeditor.js:129
a.event.on.m ckeditor.js:6
a.event.fire ckeditor.js:6
a.editor.fire ckeditor.js:7
e.extend.getData ckeditor.js:26
count /drupal/sites/all/modules/ckeditor/plugins/counter/plugin.js?t=C3HA5RM:35
a.event.on.m ckeditor.js:6
a.event.fire ckeditor.js:6
a.editor.fire ckeditor.js:7
a.focusManager.forceBlur ckeditor.js:23
a.focusManager.focus ckeditor.js:22
j.add.init.C.on.ad ckeditor.js:101
m ckeditor.js:6
a.event.fire ckeditor.js:6
d.domObject.g ckeditor.js:12

inian’s picture

Status: Postponed (maintainer needs more info) » Active
duozersk’s picture

I would love to help with this one as the counter plugin was written by me... just subscribing for now, will have more time for this issue on the weekend.

duozersk’s picture

While reviewing this issue and looking through the counter plugin code I can suggest to try commenting out this code:
editor.on( 'dataReady', count );

My thought process was that the issue is related to the CKEditor initialization so if we would comment this string then the counter plugin won't act during the initiation process. I don't have the testing environment to check for this, but it is definitely something to try and see if it helps.

Thanks
AndyB

duozersk’s picture

Actually, I have a woking website (Drupal 6) with a CCK textarea field having unlimited values - and everything is working fine with up to 11-12 fields (didn't try to add more than that...). So it is Drupal 6 with CKEditor 6.x-1.8 (stock counter plugin included with this version, not modified) and multiple CCK textarea fields; fields adding is handled by CCK.

AndyB

Alice Heaton’s picture

FileSize
604 bytes

I have an issue with the same error and backtrace, though with only one editor on the page.

I have seen it in various contexts, but the reliable way I have found to reproduce it is by :

- Highlighting some text ;
- With the text still highlighted, clicking on "Switch editor to plain text" link.

The error happens during the 'blur' event. I have read somewhere that this can happen during a certain combination of blurring and saving events because the iframe document cannot be found. This makes sense in my use case, as I'm removing the editor from the page, then it's quite possible the iframe is already gone by the time count is called.

Going on that hypothesis, I have checked and can confirm that, in my case, this is indeed the issue - when the 'blur' event is called, editor.document is null, and adding a simple test for that fixes the issue.

In my use case, this is not the fault of the counter module - plugins shouldn't be called when there is no document. (And if that was a possibility, then editor.getData should check for the eventuality). This might be the fault of Drupal's module (the way the 'Switch to plain text editor' link is handled), or the fault of CKEditor - I'm not sure.

In the mean time, as this issue seems to have happened under other circumstances, I think it wouldn't hurt for this module to implement the fix anyway.

I have attached a patch. Could the people who have experienced a similar issue test it to confirm it is the same issue ?

Alice Heaton’s picture

Status: Active » Needs review