Report an issue
Class

Watchdog (watchdog)

@ckeditor/ckeditor5-watchdog/src/watchdog

class

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>

    readonly

    An array of crashes saved as an object with the following properties:

    • message: String,
    • source: String,
    • lineno: String,
    • colno: String
  • editor : Editor

    readonly

    The current editor instance.

  • _boundErrorHandler : function

    private

    Checks if the event error comes from the editor that is handled by the watchdog (by checking the error context) and restarts the editor.

  • _config : Object | undefined

    private

    The editor configuration.

  • _crashNumberLimit : Number

    private

    Crash number limit (defaults to 3). After this limit is reached, the editor is not restarted by the watchdog. This is to prevent an infinite crash loop.

  • _creator : function

    private

    The editor creation method.

  • _data : String

    private

    The latest saved editor data.

  • _destructor : function

    private

    The editor destruction method.

  • _editor : Editor

    private

    The current editor instance.

  • _elementOrData : HTMLElement | String

    private

    The editor source element or data.

  • _lastDocumentVersion : Number

    private

    The last document version.

  • _throttledSave : function

    private

    Throttled save method. The save() method is called the specified waitingTime after throttledSave() is called, unless a new action happens in the meantime.

Methods

  • constructor( [ config ] = { [config.crashNumberLimit], [config.waitingTime] } )

    Parameters

    [ config ] : Object

    The watchdog plugin configuration.

    Properties
    [ config.crashNumberLimit ] : Number

    A threshold specifying the number of crashes when the watchdog stops restarting the editor in case of errors.

    Defaults to 3

    [ config.waitingTime ] : Number

    A minimum amount of milliseconds between saving the editor data internally.

    Defaults to 5000

  • create( elementOrData, [ config ] ) → Promise.<Watchdog>

    Creates a watched editor instance using the creator passed to the setCreator() method or the Watchdog.for() helper.

    Parameters

    elementOrData : HTMLElement | String
    [ config ] : EditorConfig

    Returns

    Promise.<Watchdog>
  • destroy() → Promise.<Watchdog>

    Destroys the current editor instance by using the destructor passed to the setDestructor() method.

    Returns

    Promise.<Watchdog>
  • restart() → Promise

    Restarts the editor instance. This method is also called whenever an editor error occurs. It fires the restart event.

    Returns

    Promise

    Fires

  • setCreator( creator )

    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 )

    Sets the function that is responsible for the editor destruction. It expects a function that should return a promise or undefined.

    watchdog.setDestructor( editor => editor.destroy() );

    Parameters

    destructor : function
  • _handleGlobalErrorEvent( evt )

    private

    Checks if the event error comes from the editor that is handled by the watchdog (by checking the error context) and restarts the editor. It handles CKEditorError errors only.

    Parameters

    evt : Event

    An error event.

    Fires

  • _isErrorComingFromThisEditor( error )

    private

    Traverses both structures to find out whether the error context is connected with the current editor.

    Parameters

    error : CKEditorError
  • _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.

Static methods

  • for( Editor )

    static

    A shorthand method for creating an instance of the watchdog. For the full usage, see the Watchdog class description.

    Usage:

    const watchdog = Watchdog.for( ClassicEditor );
    
    watchdog.create( elementOrData, config );

    Parameters

    Editor : *

    The editor class.

Events

  • error( eventInfo )

    Fired when an error occurs and the watchdog will be restarting the editor.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.

  • restart( eventInfo )

    Fired after the watchdog restarts the error in case of a crash or when the restart() method was called explicitly.

    Parameters

    eventInfo : EventInfo

    An object containing information about the fired event.