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
Properties
-
crashes : Array.<Object>
module:watchdog/editorwatchdog~EditorWatchdog#crashes
readonly inherited
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.
-
state : 'initializing' | 'ready' | 'crashed' | 'crashedPermanently' | 'destroyed'
module:watchdog/editorwatchdog~EditorWatchdog#state
inherited
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()
.
-
_crashNumberLimit : Number
module:watchdog/editorwatchdog~EditorWatchdog#_crashNumberLimit
protected inherited
Related:
-
_creator : function
module:watchdog/editorwatchdog~EditorWatchdog#_creator
protected inherited
The creation method.
Related:
-
_destructor : function
module:watchdog/editorwatchdog~EditorWatchdog#_destructor
protected inherited
The destruction method.
Related:
-
_item : Object | undefined
module:watchdog/editorwatchdog~EditorWatchdog#_item
protected inherited
The watched item.
-
_minimumNonErrorTimePeriod : Number
module:watchdog/editorwatchdog~EditorWatchdog#_minimumNonErrorTimePeriod
protected inherited
Related:
-
_now
module:watchdog/editorwatchdog~EditorWatchdog#_now
protected inherited
Returns the result of the
Date.now()
call. It can be overridden in tests to mock time as some popular approaches likesinon.useFakeTimers()
do not work well with error handling. -
_config : Object | undefined
module:watchdog/editorwatchdog~EditorWatchdog#_config
private
The editor configuration.
-
_data : Object.<String, String>
module:watchdog/editorwatchdog~EditorWatchdog#_data
private
The latest saved editor data represented as a root name -> root data object.
-
The current editor instance.
-
_elementOrData : HTMLElement | String | Object.<(String | String)>
module:watchdog/editorwatchdog~EditorWatchdog#_elementOrData
private
The editor source element or data.
-
_lastDocumentVersion : Number
module:watchdog/editorwatchdog~EditorWatchdog#_lastDocumentVersion
private
The last document version.
-
_listeners : Object.<String, Function>>
module:watchdog/editorwatchdog~EditorWatchdog#_listeners
private inherited
A dictionary of event emitter listeners.
-
_throttledSave : function
module:watchdog/editorwatchdog~EditorWatchdog#_throttledSave
private
Throttled save method. The
save()
method is called the specifiedsaveInterval
afterthrottledSave()
is called, unless a new action happens in the meantime.
Methods
-
constructor( Editor, [ watchdogConfig ] )
module:watchdog/editorwatchdog~EditorWatchdog#constructor
Parameters
Editor : *
The editor class.
[ watchdogConfig ] : WatchdogConfig
The watchdog plugin configuration.
-
create( [ elementOrData ], [ config ], [ context ] ) → Promise
module:watchdog/editorwatchdog~EditorWatchdog#create
Creates the editor instance and keeps it running, using the defined creator and destructor.
Parameters
[ elementOrData ] : HTMLElement | String | Object.<(String | String)>
The editor source element or the editor data.
[ config ] : EditorConfig
The editor configuration.
[ context ] : Object
A context for the editor.
Returns
Promise
-
destroy()
module:watchdog/editorwatchdog~EditorWatchdog#destroy
inherited
Destroys the watchdog and releases the resources.
-
off( eventName, callback )
module:watchdog/editorwatchdog~EditorWatchdog#off
inherited
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 : String
The event name.
callback : function
A callback which will be removed from event listeners.
-
on( eventName, callback )
module:watchdog/editorwatchdog~EditorWatchdog#on
inherited
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.Parameters
eventName : String
The event name.
callback : function
A callback which will be added to event listeners.
-
setCreator( creator )
module:watchdog/editorwatchdog~EditorWatchdog#setCreator
inherited
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 : function
-
setDestructor( destructor )
module:watchdog/editorwatchdog~EditorWatchdog#setDestructor
inherited
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 : function
-
_fire( eventName, args )
module:watchdog/editorwatchdog~EditorWatchdog#_fire
protected inherited
Fires an event with a given event name and arguments.
Note that this method differs from the CKEditor 5's default
EventEmitterMixin
implementation.Parameters
eventName : String
The event name.
args : *
Event arguments.
-
_isErrorComingFromThisItem( error )
module:watchdog/editorwatchdog~EditorWatchdog#_isErrorComingFromThisItem
protected
Traverses the error context and the current editor to find out whether these structures are connected to each other via properties.
Parameters
error : CKEditorError
-
_restart() → Promise
module:watchdog/editorwatchdog~EditorWatchdog#_restart
protected
Restarts the editor instance. This method is called whenever an editor error occurs. It fires the
restart
event and changes the state toinitializing
. -
_setExcludedProperties( props )
module:watchdog/editorwatchdog~EditorWatchdog#_setExcludedProperties
protected
Parameters
props : Set
-
_startErrorHandling()
module:watchdog/editorwatchdog~EditorWatchdog#_startErrorHandling
protected inherited
Starts error handling by attaching global error handlers.
-
_stopErrorHandling()
module:watchdog/editorwatchdog~EditorWatchdog#_stopErrorHandling
protected inherited
Stops error handling by detaching global error handlers.
-
_boundErrorHandler()
module:watchdog/editorwatchdog~EditorWatchdog#_boundErrorHandler
private inherited
Checks if the event error comes from the underlying item and restarts the item.
-
_cloneEditorConfiguration( config )
module:watchdog/editorwatchdog~EditorWatchdog#_cloneEditorConfiguration
private
Clones the editor configuration.
Parameters
config : Object
-
_destroy() → Promise
module:watchdog/editorwatchdog~EditorWatchdog#_destroy
private
Returns
Promise
-
_getData() → Object.<String, String>
module:watchdog/editorwatchdog~EditorWatchdog#_getData
private
Returns the editor data.
Returns
Object.<String, String>
-
_handleError( error, evt )
module:watchdog/editorwatchdog~EditorWatchdog#_handleError
private inherited
Checks if an error comes from the watched item and restarts it. It reacts to
CKEditorError
errors only.Parameters
error : Error
Error.
evt : ErrorEvent | PromiseRejectionEvent
An error event.
Fires
-
_save()
module:watchdog/editorwatchdog~EditorWatchdog#_save
private
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.
-
_shouldReactToError( error )
module:watchdog/editorwatchdog~EditorWatchdog#_shouldReactToError
private inherited
Checks whether an error should be handled by the watchdog.
Parameters
error : Error
An error that was caught by the error handling process.
-
_shouldRestart()
module:watchdog/editorwatchdog~EditorWatchdog#_shouldRestart
private inherited
Checks if the watchdog should restart the underlying item.
Events
-
error( eventInfo )
module:watchdog/editorwatchdog~EditorWatchdog#event:error
inherited
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.
-
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.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.