Node.js/NPM
Integrate Docs Embed using the NPM package for full application-level control
Steps
2
4
Create an iframe
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
userId: '123',
plan: 'premium'
}
}
});
iframe.id = "gitbook-embed-container";
iframe.style.border = "none";
iframe.style.width = "100%";
iframe.style.height = "600px";5
6
Control the embed programmatically
// 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();7
Configure the embed
frame.configure({
trademark: false,
tabs: ['assistant', 'search', 'docs'],
actions: [
{
icon: 'circle-question',
label: 'Contact Support',
onClick: () => window.open('https://support.example.com', '_blank')
}
],
greeting: { title: 'Welcome!', subtitle: 'How can I help?' },
suggestions: ['What is GitBook?', 'How do I get started?'],
tools: [/* ... */]
});API Reference
Client Factory
Frame Client Methods
Configuration Options
tabs
tabsactions
actionsgreeting
greetingsuggestions
suggestionstrademark
trademarktools
toolsFrame URL options
colorScheme
colorSchemevisitor (Authenticated Access)
visitor (Authenticated Access)Common pitfalls
Last updated
Was this helpful?