Script tag
Add Docs Embed to any website with a simple script tag
Last updated
Was this helpful?
Add Docs Embed to any website with a simple script tag
Last updated
Was this helpful?
Was this helpful?
https://docs.company.com/~gitbook/embed/script.js (replace docs.company.com with your actual docs site URL).Place this code in your HTML <head> or before the closing </body> tag:
<script src="https://docs.company.com/~gitbook/embed/script.js"></script>
<script>
// Initialize with Authenticated Access (optional)
window.GitBook('init',
{ siteURL: 'https://docs.company.com' },
{ visitor:
Use the API to navigate to pages, switch tabs, or post messages:
<script>
// Navigate to a specific page in the docs tab
window.GitBook('navigateToPage', '/getting-started');
// Switch to the assistant tab
window.GitBook('navigateToAssistant');
// Post a message to the chat
GitBook('init', options: { siteURL: string }, frameOptions?: { visitor?: {...} }) - Initialize widget with site URL and optional authenticated access
GitBook('show') - Show widget button
GitBook('hide') - Hide widget button
GitBook('open') - Open widget window
GitBook('close') - Close widget window
GitBook('toggle') - Toggle widget window
GitBook('navigateToPage', path: string) - Navigate to a specific page in the docs tab
GitBook('navigateToAssistant') - Navigate to the assistant tab
GitBook('postUserMessage', message: string) - Post a message to the chat
GitBook('clearChat') - Clear chat history
GitBook('configure', settings: {...}) - Configure widget settings (see Configuration section below)
GitBook('unload') - Completely remove the widget from the page
Configuration options are available via GitBook('configure', {...}):
Override which tabs are displayed. Defaults to your site's configuration.
Type: ('assistant' | 'docs')[]
Options:
['assistant', 'docs'] - Show both tabs
['assistant'] - Show only the assistant tab
['docs'] - Show only the docs tab
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 }>
Properties:
icon: string - Icon name. Any FontAwesome icon is supported
label: string - Button label text
onClick: () => void | Promise<void> - Callback function when clicked
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?: {...} }>
Configure the widget button that launches the embed (standalone script only). This allows you to customize the label and icon of the button that appears in the bottom-right corner of your page.
Type: { label: string, icon: 'assistant' | 'sparkle' | 'help' | 'book' }
Properties:
label: string - The text displayed on the button
icon: 'assistant' | 'sparkle' | 'help' | 'book' - The icon displayed on the button
assistant - Assistant icon
sparkle - Sparkle icon
Example:
Note: This option is only available when using the standalone script tag implementation. For React or Node.js implementations, you'll need to create your own button to trigger the embed.
Pass when initializing with GitBook('init', options, frameOptions). Used for Adaptive Content and Authenticated Access.
Type: { token?: string, unsignedClaims?: Record<string, unknown> }
Properties:
token: string (optional) - Signed JWT token
unsignedClaims: Record<string, unknown> (optional) - Unsigned claims for dynamic expressions
Script URL is incorrect β Ensure you're using your actual docs URL, not the example docs.company.com.
Calling GitBook before script loads β Wrap API calls in script.onload or place them after the script tag.
Authenticated docs not accessible β If your docs require sign-in, you must provide the visitor.token when initializing. See .
CORS or CSP errors β Ensure your site's Content Security Policy allows loading scripts and iframes from your GitBook domain.
Widget not visible β Check z-index conflicts with other elements on your page. The widget uses a high z-index by default.
Forgetting to initialize β Make sure to call GitBook('init', { siteURL: '...' }) before using other methods.
window.GitBook('configure', {
button: {
label: 'Ask',
icon: 'assistant'
}
});help - Help/question iconbook - Book icon