The context watchdog class constructor.
const watchdog = new ContextWatchdog( Context );
await watchdog.create( contextConfiguration );
await watchdog.add( item );
See the {@glink features/watchdog Watchdog feature guide} to learn more how to use this feature.
The module:core/context~Context class.
OptionalwatchdogConfig: WatchdogConfigThe watchdog configuration.
Protected_The creation method.
Protected_The destruction method.
The watched item.
Protected_A map of internal watchdogs for added items.
ReadonlycrashesAn 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,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 to initializing or crashedPermanently
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 calling watchdog.destroy().The context instance. Keep in mind that this property might be changed when the context watchdog restarts,
so do not keep this instance internally. Always operate on the ContextWatchdog#context property.
Protected_Fires an event with a given event name and arguments.
Note that this method differs from the CKEditor 5's default EventEmitterMixin implementation.
Protected_InternalChecks whether an error comes from the context instance and not from the item instances.
Protected_Restarts the context watchdog.
Protected_Starts error handling by attaching global error handlers.
Protected_Stops error handling by detaching global error handlers.
Adds items to the watchdog. Once created, instances of these items will be available using the #getItem method.
Items can be passed together as an array of objects:
await watchdog.add( [ {
id: 'editor1',
type: 'editor',
sourceElementOrData: document.querySelector( '#editor' ),
config: {
plugins: [ Essentials, Paragraph, Bold, Italic ],
toolbar: [ 'bold', 'italic', 'alignment' ]
},
creator: ( element, config ) => ClassicEditor.create( element, config )
} ] );
Or one by one as objects:
await watchdog.add( {
id: 'editor1',
type: 'editor',
sourceElementOrData: document.querySelector( '#editor' ),
config: {
plugins: [ Essentials, Paragraph, Bold, Italic ],
toolbar: [ 'bold', 'italic', 'alignment' ]
},
creator: ( element, config ) => ClassicEditor.create( element, config )
] );
Then an instance can be retrieved using the #getItem method:
const editor1 = watchdog.getItem( 'editor1' );
Note that this method can be called multiple times, but for performance reasons it is better to pass all items together.
An item configuration object or an array of item configurations.
Initializes the context watchdog. Once it is created, the watchdog takes care about recreating the context and the provided items, and starts the error handling mechanism.
await watchdog.create( {
plugins: []
} );
OptionalcontextConfig: ContextConfigThe context configuration. See module:core/context~Context.
Destroys the context watchdog and all added items. Once the context watchdog is destroyed, new items cannot be added.
await watchdog.destroy();
Returns an item instance with the given itemId.
const editor1 = watchdog.getItem( 'editor1' );
The item ID.
The item instance or undefined if an item with a given ID has not been found.
Gets the state of the given item. See #state for a list of available states.
const editor1State = watchdog.getItemState( 'editor1' );
Item ID.
The state of the item.
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.
The event name.
A callback which will be removed from event listeners.
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.
The event name.
A callback which will be added to event listeners.
Removes and destroys item(s) with given ID(s).
await watchdog.remove( 'editor1' );
Or
await watchdog.remove( [ 'editor1', 'editor2' ] );
Item ID or an array of item IDs.
Sets the function that is responsible for the context creation.
It expects a function that should return a promise (or undefined).
watchdog.setCreator( config => Context.create( config ) );
Sets the function that is responsible for the context destruction.
Overrides the default destruction function, which destroys only the context instance.
It expects a function that should return a promise (or undefined).
watchdog.setDestructor( context => {
// Do something before the context is destroyed.
return context
.destroy()
.then( () => {
// Do something after the context is destroyed.
} );
} );
A watchdog for the module:core/context~Context class.
See the {@glink features/watchdog Watchdog feature guide} to learn the rationale behind it and how to use it.