Skip to content

Context Messages

When a user opens a supported profile with an active plugin, Livespace sends the current record's data to the embedded iframe using the browser postMessage API. The message is sent once when the profile loads, and again if the user navigates to a different record without a full page reload.

Message format

{
  type: 'livespace-plugin:context',
  payload: {
    deal?:    { id: string /* UUID */, name: string },
    company?: { id: string /* UUID */, name: string },
    person?:  { id: string /* UUID */, firstName: string, lastName: string },
    space?:   { id: string /* UUID */, name: string },
    user:     { id: string /* UUID */ }
  }
}
Profile type Payload key Fields
Deal deal id (UUID), name
Company company id (UUID), name
Person person id (UUID), firstName, lastName
Space space id (UUID), name
All profiles user id (UUID) — always present

Key rules

  • Exactly one entity key (deal, company, person, or space) is present — determined by the profile the user is currently viewing.
  • user.id is always present and is the only reliable source of the logged-in user's identity.
  • The host may re-send context if the user navigates to another record. Treat each message as a fresh state and re-render accordingly.
  • person uses firstName and lastName instead of a single name field.

Receiving the context in your application

Listen for message events on window. Always parse the payload defensively and verify type before acting.

window.addEventListener('message', (event) => {
  let data;
  try {
    data = typeof event.data === 'string' ? JSON.parse(event.data) : event.data;
  } catch (e) { return; }

  if (!data || data.type !== 'livespace-plugin:context') return;

  const { deal, company, person, space, user } = data.payload;

  console.log('Current user ID:', user.id);

  if (deal) {
    console.log('Deal:', deal.id, deal.name);
    // load deal-specific data
  } else if (company) {
    console.log('Company:', company.id, company.name);
  } else if (person) {
    console.log('Person:', person.id, person.firstName, person.lastName);
  } else if (space) {
    console.log('Space:', space.id, space.name);
  }
});