API Reference

Learn more about the methods available to use when working with Docs Embed programmatically

Docs Embed provides different APIs depending on how you integrate it. This reference covers all available methods across integration methods.

Method Comparison

Method
Standalone Script
NPM Package
React Components

Initialize

GitBook('init', options, frameOptions)

createGitBook(options)

<GitBookProvider siteURL="...">

Get frame URL

❌ (handled internally)

client.getFrameURL(options)

useGitBook().getFrameURL(options)

Create frame client

❌ (handled internally)

client.createFrame(iframe)

useGitBook().createFrame(iframe)

Show/Hide widget

GitBook('show') / GitBook('hide')

❌

❌

Open/Close window

GitBook('open') / GitBook('close') / GitBook('toggle')

❌

❌

Navigate to page

GitBook('navigateToPage', path)

frame.navigateToPage(path)

Via frame client

Navigate to assistant

GitBook('navigateToAssistant')

frame.navigateToAssistant()

Via frame client

Post message

GitBook('postUserMessage', message)

frame.postUserMessage(message)

Via frame client

Clear chat

GitBook('clearChat')

frame.clearChat()

Via frame client

Configure

GitBook('configure', settings)

frame.configure(settings)

Props on <GitBookFrame>

Event listeners

❌

frame.on(event, listener)

Via frame client

Unload

GitBook('unload')

❌

❌

Standalone Script API

Initialization

GitBook('init', options, frameOptions)

Initialize the widget with site URL and optional authenticated access.

Parameters:

  • options: { siteURL: string } - Your GitBook docs site URL

  • frameOptions: { visitor?: { token?: string, unsignedClaims?: Record<string, unknown> } } (optional) - Authenticated access options

Example:

Widget Control

Show the widget

Display the GitBook widget if it has been hidden.

Example:

Hide the widget

Hide the GitBook widget without unloading it.

Example:

Open the window

Open the Docs Embed window.

Example:

Close the window

Close the Docs Embed window.

Example:

Toggle the window

Toggle the Docs Embed window open or closed.

Example:

Unload the widget

Completely remove the GitBook widget from your site.

Example:

GitBook('navigateToPage', path)

Navigate to a specific page within your GitBook docs by its path.

Parameters:

  • path (string): The path to the page you want to navigate to

Example:

GitBook('navigateToAssistant')

Navigate directly to the Assistant tab.

Example:

Chat

GitBook('postUserMessage', message)

Post a message to the chat as if the user typed it.

Parameters:

  • message (string): The message to post to the chat

Example:

GitBook('clearChat')

Clear all messages from the current chat session.

Example:

Configuration

GitBook('configure', settings)

Configure the embed with customization options. See the Configuration section for available options.

Example:

NPM Package API

Client Factory

createGitBook(options)

Create a GitBook client instance.

Parameters:

  • options: { siteURL: string } - Your GitBook docs site URL

Returns: GitBookClient

Example:

client.getFrameURL(options)

Get the iframe URL with optional authenticated access.

Parameters:

  • options: { visitor?: { token?: string, unsignedClaims?: Record<string, unknown> } } (optional)

Returns: string

Example:

client.createFrame(iframe)

Create a frame client to communicate with the iframe.

Parameters:

  • iframe: HTMLIFrameElement - The iframe element

Returns: GitBookFrameClient

Example:

Frame Client Methods

frame.navigateToPage(path)

Navigate to a specific page in the docs tab.

Parameters:

  • path: string - The path to the page

frame.navigateToAssistant()

Switch to the assistant tab.

frame.postUserMessage(message)

Post a message to the chat.

Parameters:

  • message: string - The message to post

frame.clearChat()

Clear chat history.

frame.configure(settings)

Configure the embed. See the Configuration section for available options.

frame.on(event, listener)

Register an event listener.

Parameters:

  • event: string - The event name

  • listener: Function - The callback function

Returns: () => void - Unsubscribe function

Example:

React Components API

See the React integration guide for component props and the useGitBook hook API.

Last updated

Was this helpful?