User Events

Listen for certain events based on a user’s behavior in the Webflow Designer, or notify a user of important events.

Notify a User

You can send a notification to a user through your Designer Extension. Notifications will appear in the top right corner of the designer, and can be styled as either a success, error, or general information message. Notifications are helpful to let a user know that they have - or have not - completed a task successfully. Additionally, it’s helpful to let a user know about any unexpected errors your app may encounter.

To notify a user, use the webflow.notify() method.

Subscribe to an event

Additionally, you can subscribe to events in the designer using the subscribe method by subscribing to different event types. Currently, you can subscribe to three event types in the designer:

  • **Detect a new Selected Element: **You can subscribe to the selectedElement event to be notified whenever a different element is selected in the Webflow designer. This is useful if you want to perform specific actions or updates based on the currently selected element. A null element signifies that no element is selected
  • **Detect a Breakpoint Change: **Use the mediaquery event to stay informed as the designer switches between breakpoints for desktops, tablets, or smartphones.
  • Detect a Page Change: The currentPage event allows you to respond when the user switches to a different page in the Webflow designer. This can be handy if you want to load additional data or perform actions specific to the selected page.

Using Callbacks

Callback functions are used to handle and respond to events triggered by the Webflow Designer. Add your callback function as a parameter to the subscribe function to determine how to handle events in the designer. Here are some general tips for writing callbacks to handle events:

  • Keep them Lightweight: Callbacks should be fast to execute to ensure a responsive user experience.
  • **Error Handling: **Always include error handling in your callbacks to manage exceptions gracefully.
  • Unsubscribe When Necessary: Remember to unsubscribe from events when your app no longer needs to listen to them, to prevent memory leaks and unnecessary processing.