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
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)
GitBook('init', options, frameOptions)Initialize the widget with site URL and optional authenticated access.
Parameters:
options:{ siteURL: string }- Your GitBook docs site URLframeOptions:{ 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:
Navigation
GitBook('navigateToPage', path)
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')
GitBook('navigateToAssistant')Navigate directly to the Assistant tab.
Example:
Chat
GitBook('postUserMessage', message)
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')
GitBook('clearChat')Clear all messages from the current chat session.
Example:
Configuration
GitBook('configure', settings)
GitBook('configure', settings)Configure the embed with customization options. See the Configuration section for available options.
Example:
NPM Package API
Client Factory
createGitBook(options)
createGitBook(options)Create a GitBook client instance.
Parameters:
options:{ siteURL: string }- Your GitBook docs site URL
Returns: GitBookClient
Example:
client.getFrameURL(options)
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)
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)
frame.navigateToPage(path)Navigate to a specific page in the docs tab.
Parameters:
path:string- The path to the page
frame.navigateToAssistant()
frame.navigateToAssistant()Switch to the assistant tab.
frame.postUserMessage(message)
frame.postUserMessage(message)Post a message to the chat.
Parameters:
message:string- The message to post
frame.clearChat()
frame.clearChat()Clear chat history.
frame.configure(settings)
frame.configure(settings)Configure the embed. See the Configuration section for available options.
frame.on(event, listener)
frame.on(event, listener)Register an event listener.
Parameters:
event:string- The event namelistener: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?