iFrame Guide

Read this if you want to add OfficeX as a UX lego within your app

Anonymous OfficeX is designed for whitelabel with zero dependencies. Any developer can add anon workspaces to their app in just 2 mins.

The below iframe examples showcase how easy it is to get started. There are two modes:

  • ephemeral offline mode for purely clientside UX without cloud

  • cloud injected mode for controlled authentication with cloud

Both modes can use iframe.postMessage() commands to control the child iframe from purely clientside. Scroll down to see those commands.

Ephemeral offline mode is a pure clientside iframe with no cloud or backend. Its primary value is for organizational UX. It is ideal for single-use tools such as YouTube Downloaders and PDF generators.

The below code snippet is a barebones implementation in raw HTML. It has zero dependencies so you can just copy paste it directly.

terminalRun in Codepen

<iframe
  id="officex-iframe"
  src="https://officex.app"
  sandbox="allow-same-origin allow-scripts allow-downloads allow-popups"
></iframe>
<script>
  const iframeElement = document.getElementById("officex-iframe");
  iframeElement.onload = () => {
    iframeElement.contentWindow.postMessage(
      { type: "OFFICEX_INIT", data: { ephemeral: {} }, tracer: "my-tracer" },
      "https://officex.app"
    );
  };
</script>

Additionally, you can provide extra arguments to the ephemeral mode like so:

  • profile_entropy is like a password seed phrase to deterministically generate an officex user (which is really just a crypto wallet). The same secret_entropy string will create the exact same wallet every time.

  • org_entropy is the same, except for deterministically generating an officex organization. While it is possible to use org_entropy in ephemeral iframes, it is currently not possible in cloud.

The most common reason to use entropy strings is to avoid messy workspaces. Using unique new entropy will create a fresh new organization entirely.

Once you've initialized your iframes, you have two ways to control them:

  • REST API (cloud only)

  • iframe.postMessage() (works for all)

The REST API method is straightforward, as the frontend will automatically reflect the backend server state. Meanwhile the iframe.postMessage() commands are a custom protocol that works purely clientside. See the commands below.

iFrame PostMessage Commands

iframe.postMessage() commands are a custom protocol that works purely clientside. The commands follow a pattern like so:

The command gets sent to the child iframe OfficeX. It will process it and return back a message to parent webpage. You must listen to the message event from browser. Learn more about iframe.postMessage() here in mdn browser docs.arrow-up-right

For a full end-to-end demo of iframe messaging, view the below interactive demo and its github repo.

terminalInteractive Demo githubView Github

The list of iframe commands are below.

chevron-rightIFrameCommandType.INIThashtag

Mandatory command in order to initiate the iframe. Include the auth credentials to switch to the right organization and profile.

ephemeral offline

injected cloud

chevron-rightIFrameCommandType.ABOUThashtag

Get info about the current organization and profile in the iframe. Useful for status checks, especially when dealing with multi-tenant environments.

chevron-rightIFrameCommandType.AUTH_TOKENhashtag

Get auth token of the current organization and profile in the iframe. Useful for doing clientside REST API calls, helping simplify in multi-tenant environments without involving backend.

chevron-rightIFrameCommandType.NAVIGATEhashtag

Navigate the child iframe to a url. Useful for controlling the child iframe UX from your parent webpage, as if it were part of your app.

Use this in combo with shortlinksarrow-up-right if you want to avoid exposing auth credentials to clients.

chevron-rightIFrameCommandType.DIRECTORY_ACTION | CREATE_FILEhashtag

Create a file and save it to your child iframe. Files can be uploaded either as a raw_url string or as a base64 file of max 50mb size. For large file uploads, use the OfficeX UMD <script> (coming soon).

raw_url

base64

chevron-rightIFrameCommandType.DIRECTORY_ACTION | CREATE_FOLDERhashtag

Create a folder and save it to your child iframe.

You can see all the official iframe types for typescript on npm github officexapp/types

githubView iFrame Types

Easy Multi-iFrame Management

If your users are often hopping between multiple organizations, we recommend using deterministic iframe profilesarrow-up-right with cloud organizations, as that lets you avoid a lot of headache managing api keys per user per org. The ephemeral offline profiles can use their crypto identities to generate temp auth signatures as a form of universal auth for all organizations.

Otherwise you'll need to inject api key per user per organization, and send those to credentials to frontend per user session. We highly recommend you read about common iframe auth flowsarrow-up-right to understand the tradeoffs.

Feature Flags

App developers can control the OfficeX experience shown to users. While production https://officex.apparrow-up-right has sensible defaults, you can customize many options as follows:

This feature is coming soon


iFrames are the primary way to implement OfficeX as a UX lego inside your app. But for some use cases, you might want to just get access to a users pre-existing organization. For those cases, continue to Grant Existing guide next below.

Last updated