EditorWatchdog (watchdog)
@ckeditor/ckeditor5-watchdog/src/editorwatchdog
A watchdog for CKEditor 5 editors.
See the Watchdog feature guide to learn the rationale behind it and how to use it.
Filtering
Type parameters
-
TEditor : extends Editor
Properties
-
An array of crashes saved as an object with the following properties:
message
:String
,stack
:String
,date
:Number
,filename
:String | undefined
,lineno
:Number | undefined
,colno
:Number | undefined
,
-
The current editor instance.
-
Specifies the state of the item watched by the watchdog. The state can be one of the following values:
initializing
– Before the first initialization, and after crashes, before the item is ready.ready
– A state when the user can interact with the item.crashed
– A state when an error occurs. It quickly changes toinitializing
orcrashedPermanently
depending on how many and how frequent errors have been caught recently.crashedPermanently
– A state when the watchdog stops reacting to errors and keeps the item it is watching crashed,destroyed
– A state when the item is manually destroyed by the user after callingwatchdog.destroy()
.
-
protected
_creator : EditorCreatorFunction<TEditor>
module:watchdog/editorwatchdog~EditorWatchdog#_creator
-
protected
_destructor : ( Editor ) => Promise<unknown>
module:watchdog/editorwatchdog~EditorWatchdog#_destructor
The destruction method.
-
The editor configuration.
-
The latest saved editor data represented as a root name -> root data object.
-
private
_editables : Record<string, HTMLElement>
module:watchdog/editorwatchdog~EditorWatchdog#_editables
The latest record of the editor editable elements. Used to restart the editor.
-
The current editor instance.
-
private
_elementOrData : string | HTMLElement | Record<string, string> | Record<string, HTMLElement> | undefined
module:watchdog/editorwatchdog~EditorWatchdog#_elementOrData
The editor source element or data.
-
private
_excludedProps : Set<unknown> | undefined
module:watchdog/editorwatchdog~EditorWatchdog#_excludedProps
-
Specifies whether the editor was initialized using document data (
true
) or HTML elements (false
). -
private
_lastDocumentVersion : number | undefined
module:watchdog/editorwatchdog~EditorWatchdog#_lastDocumentVersion
The last document version.
-
private
_lifecyclePromise : null | Promise<unknown>
module:watchdog/editorwatchdog~EditorWatchdog#_lifecyclePromise
A promise associated with the life cycle of the editor (creation or destruction processes).
It is used to prevent the initialization of the editor if the previous instance has not been destroyed yet, and conversely, to prevent the destruction of the editor if it has not been initialized.
-
private
_throttledSave : DebouncedFunc<() => void>
module:watchdog/editorwatchdog~EditorWatchdog#_throttledSave
Throttled save method. The
save()
method is called the specifiedsaveInterval
afterthrottledSave()
is called, unless a new action happens in the meantime.
Methods
-
constructor( Editor = { Editor.create }, watchdogConfig )
module:watchdog/editorwatchdog~EditorWatchdog#constructor
Type parameters
TEditor : extends [object Object] = default
Parameters
Editor : null | object
The editor class.
PropertiesEditor.create : Promise<TEditor>
watchdogConfig : WatchdogConfig
The watchdog plugin configuration.
Defaults to
{}
-
create( elementOrData, config, [ context ] ) → Promise<unknown>
module:watchdog/editorwatchdog~EditorWatchdog#create
Creates the editor instance and keeps it running, using the defined creator and destructor.
Parameters
elementOrData : string | HTMLElement | Record<string, string> | Record<string, HTMLElement>
The editor source element or the editor data.
Defaults to
...
config : EditorConfig
The editor configuration.
Defaults to
...
[ context ] : Context
A context for the editor.
Returns
Promise<unknown>
-
destroy() → Promise<unknown>
module:watchdog/editorwatchdog~EditorWatchdog#destroy
Destroys the watchdog and the current editor instance. It fires the callback registered in
setDestructor()
and uses it to destroy the editor instance. It also sets the state todestroyed
.Returns
Promise<unknown>
-
Stops listening to the specified event name by removing the callback from event listeners.
Note that this method differs from the CKEditor 5's default
EventEmitterMixin
implementation.Parameters
eventName : keyof EventMap
The event name.
callback : unknown
A callback which will be removed from event listeners.
Returns
void
-
Starts listening to a specific event name by registering a callback that will be executed whenever an event with a given name fires.
Note that this method differs from the CKEditor 5's default
EventEmitterMixin
implementation.Type parameters
K : extends keyof EventMap
Parameters
eventName : K
The event name.
callback : EventCallback<K>
A callback which will be added to event listeners.
Returns
void
-
setCreator( creator ) → void
module:watchdog/editorwatchdog~EditorWatchdog#setCreator
Sets the function that is responsible for the editor creation. It expects a function that should return a promise.
watchdog.setCreator( ( element, config ) => ClassicEditor.create( element, config ) );
Parameters
creator : EditorCreatorFunction<TEditor>
Returns
void
-
setDestructor( destructor ) → void
module:watchdog/editorwatchdog~EditorWatchdog#setDestructor
Sets the function that is responsible for the editor destruction. Overrides the default destruction function, which destroys only the editor instance. It expects a function that should return a promise or
undefined
.watchdog.setDestructor( editor => { // Do something before the editor is destroyed. return editor .destroy() .then( () => { // Do something after the editor is destroyed. } ); } );
Parameters
destructor : ( Editor ) => Promise<unknown>
Returns
void
-
internal
_isErrorComingFromThisItem( error ) → boolean
module:watchdog/editorwatchdog~EditorWatchdog#_isErrorComingFromThisItem
Traverses the error context and the current editor to find out whether these structures are connected to each other via properties.
Parameters
error : CKEditorError
Returns
boolean
-
internal
_setExcludedProperties( props ) → void
module:watchdog/editorwatchdog~EditorWatchdog#_setExcludedProperties
-
protected inherited
_fire( eventName, args ) → void
module:watchdog/editorwatchdog~EditorWatchdog#_fire
-
Restarts the editor instance. This method is called whenever an editor error occurs. It fires the
restart
event and changes the state toinitializing
.Returns
Promise<unknown>
Fires
-
protected inherited
_startErrorHandling() → void
module:watchdog/editorwatchdog~EditorWatchdog#_startErrorHandling
-
protected inherited
_stopErrorHandling() → void
module:watchdog/editorwatchdog~EditorWatchdog#_stopErrorHandling
-
private
_cloneEditorConfiguration( config ) → EditorConfig
module:watchdog/editorwatchdog~EditorWatchdog#_cloneEditorConfiguration
-
-
-
private
_getEditables() → Record<string, HTMLElement>
module:watchdog/editorwatchdog~EditorWatchdog#_getEditables
For each attached model root, returns its HTML editable element (if available).
Returns
Record<string, HTMLElement>
-
Saves the editor data, so it can be restored after the crash even if the data cannot be fetched at the moment of the crash.
Returns
void
Events
-
Fired when a new
CKEditorError
error connected to the watchdog instance occurs and the watchdog will react to it.watchdog.on( 'error', ( evt, { error, causesRestart } ) => { console.log( 'An error occurred.' ); } );
Parameters
eventInfo : EventInfo
An object containing information about the fired event.
<anonymous> : WatchdogErrorEventData
-
restart( eventInfo )
module:watchdog/editorwatchdog~EditorWatchdog#event:restart
Fired after the watchdog restarts the error in case of a crash.
Parameters
eventInfo : EventInfo
An object containing information about the fired event.
-
Fired when the watchdog state changed.
Parameters
eventInfo : EventInfo
An object containing information about the fired event.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.