Node.js/NPM
Integrate Docs Embed using the NPM package for full application-level control
Last updated
Was this helpful?
Integrate Docs Embed using the NPM package for full application-level control
Last updated
Was this helpful?
Was this helpful?
@gitbook/embed to your project:For the complete API reference and source code, see the @gitbook/embed package on GitHub.
Generate an iframe element and set its source to the embed URL:
const iframe = document.createElement("iframe");
iframe.src = gitbook.getFrameURL({
visitor: {
token: 'your-jwt-token', // Optional: for Adaptive Content or Authenticated Access
unsignedClaims: { // Optional: custom claims for dynamic expressions
Use the frame instance to interact with the embed:
// Navigate to a specific page in the docs tab
frame.navigateToPage("/getting-started");
// Switch to the assistant tab
frame.navigateToAssistant();
// Post a message to the chat
frame.postUserMessage("How do I get started?");
// Clear chat history
frame.clearChat();createGitBook(options: { siteURL: string }) β GitBookClient
client.getFrameURL(options?: { visitor?: {...} }) β string - Get the iframe URL with optional authenticated access
client.createFrame(iframe: HTMLIFrameElement) β GitBookFrameClient - Create a frame client to communicate with the iframe
frame.navigateToPage(path: string) β void - Navigate to a specific page in the docs tab
frame.navigateToAssistant() β void - Switch to the assistant tab
frame.postUserMessage(message: string) β void - Post a message to the chat
frame.clearChat() β void - Clear chat history
frame.configure(settings: Partial<GitBookEmbeddableConfiguration>) β void - Configure the embed
frame.on(event: string, listener: Function) β () => void - Register event listener (returns unsubscribe function)
Configuration options are available via frame.configure({...}):
Override which tabs are displayed. Defaults to your site's configuration.
Type: ('assistant' | 'docs')[]
Custom action buttons rendered in the sidebar alongside tabs. Each action button triggers a callback when clicked.
Note: This was previously named buttons. Use actions instead.
Type: Array<{ icon: string, label: string, onClick: () => void }>
Welcome message displayed in the Assistant tab.
Type: { title: string, subtitle: string }
Suggested questions displayed in the Assistant welcome screen.
Type: string[]
Custom AI tools to extend the Assistant. See Creating custom tools for details.
Type: Array<{ name: string, description: string, inputSchema: object, execute: Function, confirmation?: {...} }>
Pass to getFrameURL({ visitor: {...} }). Used for Adaptive Content and Authenticated Access.
Type: { token?: string, unsignedClaims?: Record<string, unknown> }
Forgetting to install the package β Run npm install @gitbook/embed before importing.
Missing siteURL β The siteURL option is required and must match your published docs site.
iFrame not rendering β Ensure the parent container has sufficient width/height for the iframe to display.
Frame methods called before initialization β Wait until createFrame() completes before calling frame methods.
Not unsubscribing from events β Remember to call the unsubscribe function returned by frame.on() to prevent memory leaks.
Using old API methods β Methods like open(), close(), toggle(), and destroy() are not available in the NPM package. Use the frame client methods instead.
npm install @gitbook/embed