FastComments.com

Add Inline Live Comments To Documents, Books, Etc

FastComments Collab Chat enables users to highlight and annotate any text content on your website, creating threaded discussions tied to specific text selections. Users can select words, sentences, or entire paragraphs to start collaborative conversations directly within your content.

This feature is perfect for editorial feedback, collaborative reading environments, educational platforms, document review, and any scenario where you want contextual discussions anchored to specific text.

Note that these docs are specific to the Collab Chat functionality. You can add commenting for content with lots of pages, like Books, with thread-per-page, without using collab chat. FastComments also does not charge per-page or per-thread. Collab Chat is specifically when you want to allow users to select text and comment on the highlighted section of text.

You can see an example here.

Examples Internal Link

Basic Example

The simplest way to use Collab Chat is to target a single content container. This example shows how to enable text annotations on an article:

Basic Collab Chat Example
Copy CopyRun External Link
1
2<!DOCTYPE html>
3<html>
4<head>
5 <title>My Article with Collab Chat</title>
6</head>
7<body>
8 <div id="article-content" style="min-height: 500px">
9 <h1>My Article Title</h1>
10 <p>This is a paragraph that users can annotate. Simply highlight any text to start a discussion!</p>
11 <p>You can have multiple paragraphs, and users can highlight text across any of them.</p>
12 </div>
13
14 <script src="https://cdn.fastcomments.com/js/embed-collab-chat.min.js"></script>
15 <script>
16 FastCommentsCollabChat(document.getElementById('article-content'), {
17 tenantId: 'demo'
18 });
19 </script>
20</body>
21</html>
22

Example with Custom URL ID (Per Book Page, Article, etc)

By default, Collab Chat uses the page URL combined with the element path and text range to identify conversations. You can provide a custom urlId to have more control over how conversations are grouped:

Collab Chat with Custom URL ID
Copy Copy
1
2<script src="https://cdn.fastcomments.com/js/embed-collab-chat.min.js"></script>
3<script>
4 FastCommentsCollabChat(document.getElementById('article-content'), {
5 tenantId: 'demo',
6 urlId: 'book-one-page-2'
7 });
8</script>
9

This is useful if your URL structure changes but you want to maintain the same conversations, or if you want to share the same conversation annotations across multiple pages.

Example with Dark Mode

If your site has a dark background, enable dark mode support to ensure the chat UI looks correct:

Collab Chat with Dark Mode
Copy CopyRun External Link
1
2<!DOCTYPE html>
3<html>
4<head>
5 <title>My Article with Collab Chat - Dark Mode</title>
6 <style>
7 body {
8 background-color: #1a1a1a !important;
9 color: #e0e0e0 !important;
10 font-family: system-ui, -apple-system, sans-serif;
11 padding: 20px;
12 margin: 0;
13 }
14 #article-content {
15 max-width: 800px;
16 margin: 0 auto;
17 background-color: #2d2d2d;
18 padding: 20px;
19 border-radius: 8px;
20 }
21 h1 {
22 color: #ffffff !important;
23 }
24 p {
25 color: #e0e0e0 !important;
26 line-height: 1.6;
27 }
28 .fastcomments-collab-chat-top-bar {
29 background-color: #2d2d2d !important;
30 color: #e0e0e0 !important;
31 border-bottom: 1px solid #444 !important;
32 }
33 </style>
34</head>
35<body>
36 <div id="article-content" style="min-height: 500px">
37 <h1>My Article Title</h1>
38 <p>This is a paragraph that users can annotate. Simply highlight any text to start a discussion!</p>
39 <p>You can have multiple paragraphs, and users can highlight text across any of them.</p>
40 </div>
41
42 <script src="https://cdn.fastcomments.com/js/embed-collab-chat.min.js"></script>
43 <script>
44 FastCommentsCollabChat(document.getElementById('article-content'), {
45 tenantId: 'demo',
46 hasDarkBackground: true
47 });
48 </script>
49</body>
50</html>
51

Example with Top Bar Disabled

By default, Collab Chat shows a top bar with user count and discussion count. You can disable it:

Collab Chat with Top Bar Disabled
Copy CopyRun External Link
1
2<!DOCTYPE html>
3<html>
4<head>
5 <title>My Article with Collab Chat - No Top Bar</title>
6</head>
7<body>
8 <div id="article-content" style="min-height: 500px">
9 <h1>My Article Title</h1>
10 <p>This is a paragraph that users can annotate. Simply highlight any text to start a discussion!</p>
11 <p>You can have multiple paragraphs, and users can highlight text across any of them.</p>
12 </div>
13
14 <script src="https://cdn.fastcomments.com/js/embed-collab-chat.min.js"></script>
15 <script>
16 FastCommentsCollabChat(document.getElementById('article-content'), {
17 tenantId: 'demo',
18 topBarTarget: null
19 });
20 </script>
21</body>
22</html>
23

Example with Comment Count Callback

You can track when comments are added or updated using the commentCountUpdated callback:

Collab Chat with Comment Count Callback
Copy Copy
1
2<script src="https://cdn.fastcomments.com/js/embed-collab-chat.min.js"></script>
3<script>
4 FastCommentsCollabChat(document.getElementById('article-content'), {
5 tenantId: 'demo',
6 commentCountUpdated: function(count) {
7 console.log('Total comments:', count);
8 document.getElementById('comment-badge').textContent = count;
9 }
10 });
11</script>
12

Example with Multiple Sections

You can initialize Collab Chat on multiple separate sections of your page. Each section will have its own independent annotations:

Collab Chat on Multiple Sections
Copy Copy
1
2<div id="intro-section">
3 <h2>Introduction</h2>
4 <p>Content for the introduction...</p>
5</div>
6
7<div id="main-section">
8 <h2>Main Content</h2>
9 <p>Content for the main article...</p>
10</div>
11
12<script src="https://cdn.fastcomments.com/js/embed-collab-chat.min.js"></script>
13<script>
14 // Initialize on intro section
15 FastCommentsCollabChat(document.getElementById('intro-section'), {
16 tenantId: 'demo',
17 urlId: 'my-article-intro'
18 });
19
20 // Initialize on main section
21 FastCommentsCollabChat(document.getElementById('main-section'), {
22 tenantId: 'demo',
23 urlId: 'my-article-main'
24 });
25</script>
26

Adding Live Commenting to Online Books Internal Link

You can initialize Collab Chat per page if desired, and have separate threads per page, simply pass the urlId parameter a value like book-one-page1. This configuration also works for the normal commenting widget.

Text Selection Behavior Internal Link

How Text Selection Works

When users select text within the Collab Chat container, the widget captures that selection and allows them to start a discussion. The selection can be as small as a single word or as large as multiple paragraphs spanning different elements.

Selection Delay

On desktop devices, there's a 3.5 second delay between when a user selects text and when the discussion prompt appears. This prevents the UI from flickering when users are simply highlighting text to copy or read. On mobile devices, the prompt appears immediately since text selection is more deliberate on touch screens.

Unique Conversation IDs

Each conversation gets a unique urlId that combines the page URL, the DOM element path, and the serialized text range. This ensures that each text selection creates a distinct conversation that can be found again later.

If you provide a custom urlId in your configuration, it will be combined with the element path and text range to create the final identifier.

Visual Highlights

When a discussion exists for a particular text selection, that text receives a visual highlight. The highlight is implemented using background colors and appears on hover or when the associated chat window is open.

The highlighting system works by wrapping the selected text in a special element that can be styled. This approach ensures that highlights remain accurate even when the underlying HTML structure is complex.

Chat Window Positioning

When a user clicks on a highlight or creates a new annotation, a chat window appears near the selected text. The widget automatically calculates the best position for this window based on available viewport space.

The positioning system uses CSS classes like to-right, to-left, to-top, and to-bottom to indicate which direction the chat window should extend from the highlight. On mobile devices (screens under 768px wide), the chat window always appears fullscreen for better usability.

Chat Window Dimensions

Chat windows are 410px wide on desktop with 20px spacing and a 16px visual arrow pointing to the highlighted text. These dimensions are fixed to ensure consistent behavior, but you can customize the appearance with CSS.

Cross-Element Selections

Users can select text that spans multiple HTML elements, such as highlighting from the middle of one paragraph through the start of another. The range serialization system handles this correctly and will highlight all the selected text even across element boundaries.

Browser Compatibility

The text selection system uses the standard window.getSelection() API which is supported in all modern browsers. For older versions of Internet Explorer, it falls back to document.selection for compatibility.

Selection Persistence

Once a conversation is created for a text selection, that annotation persists even if the page is reloaded. The serialized range and DOM path allow the widget to restore highlights in the exact same location when users return to the page.

This works reliably as long as your page content remains stable. If you change the text content or restructure your HTML, existing annotations may no longer align correctly with the text. For this reason, it's best to avoid major content changes on pages with active annotations, or consider migrating annotations when content changes are necessary.

Customization Internal Link

Dark Mode Support

Dynamic Dark Mode

If your site's dark mode is controlled by adding a .dark class to the body element, the Collab Chat UI will automatically respect this without requiring reinitialization. The widget's styles are designed to respond to the presence of this class.

Dark Mode CSS Example
Copy Copy
1
2/* Your dark mode CSS */
3body.dark {
4 background: #1a1a1a;
5 color: #ffffff;
6}
7

Custom Styling with CSS

You can customize the appearance of highlights, chat windows, and other elements using CSS. The widget adds specific classes that you can target in your stylesheet.

Text highlights use the FastComments comment bubble styling system, so any customizations you've applied to the standard commenting widget will also affect Collab Chat.

Top Bar Customization

The top bar shows the number of users online and the number of discussions. You can customize its position by providing a custom element as the topBarTarget:

Custom Top Bar Location
Copy Copy
1
2FastCommentsCollabChat(element, {
3 tenantId: 'demo',
4 topBarTarget: document.getElementById('my-custom-header')
5});
6

Or disable it entirely by setting it to null:

Disable Top Bar
Copy Copy
1
2FastCommentsCollabChat(element, {
3 tenantId: 'demo',
4 topBarTarget: null
5});
6

Mobile Behavior

On screens under 768px wide, Collab Chat automatically switches to a mobile-optimized layout. Chat windows appear fullscreen instead of floating next to the text, and the selection delay is removed for more immediate interaction.

This behavior is built-in and doesn't require any configuration. The widget detects screen size automatically and adjusts accordingly.

Chat Window Appearance

Chat windows are 410px wide on desktop with a 16px arrow pointing to the highlighted text. The windows position themselves automatically based on available viewport space, using positioning classes like to-right, to-left, to-top, and to-bottom.

You can add custom CSS to adjust colors, fonts, spacing, or other visual properties of these windows. The chat windows use the same component structure as the standard FastComments widget, so they inherit any global customizations you've applied.

Localization

Collab Chat supports all the same localization options as the standard FastComments widget. Set the locale option to display UI text in different languages:

Set Locale
Copy Copy
1
2FastCommentsCollabChat(element, {
3 tenantId: 'demo',
4 locale: 'es' // Spanish
5});
6

FastComments supports dozens of languages. The locale setting affects all UI text including prompts, buttons, and placeholder text.

Inherited Customization Options

Since Collab Chat extends the standard commenting widget, it inherits all customization options from the base widget. This includes custom CSS classes, custom translations, avatar customization, date formatting, and much more.

See the main FastComments customization documentation for the complete list of customization options available.

Working with Custom Fonts

If your site uses custom fonts, the Collab Chat UI will inherit those fonts from your page's CSS. You may have to create a widget customization rule and @import any fonts in the custom CSS in that rule if you want the floating chat window to use the same fonts.

Live Sync Internal Link

Real-Time Updates

Collab Chat uses WebSocket connections to sync all conversations in real-time across all connected users. When someone creates a new annotation, adds a comment, or deletes a discussion, all other users viewing the same page see the update immediately without refreshing.

How WebSocket Sync Works

When you initialize Collab Chat, the widget establishes a WebSocket connection to the FastComments servers. This connection remains open for the duration of the user's session and listens for updates related to the current page.

The WebSocket system uses three types of broadcast messages for Collab Chat. The new-text-chat event fires when someone creates a new annotation on the page. The updated-text-chat event fires when someone updates an existing conversation. The deleted-text-chat event fires when someone deletes an annotation.

Broadcast ID System

To prevent echo effects where users see their own actions broadcast back to them, each update includes a unique broadcastId. When a user creates or updates an annotation, their client generates a UUID for that operation. When the WebSocket broadcasts the update back to all clients, the originating client ignores the update because it matches its own broadcastId.

This ensures smooth interaction where users see their changes immediately in the UI without waiting for the round-trip through the server, while still ensuring all other users get the update.

Live User Count

The top bar displays the number of users currently viewing the page. This count updates in real-time as users join and leave. The user count is provided through the same WebSocket connection and increments/decrements automatically based on connection and disconnection events.

Connection Resilience

If the WebSocket connection drops due to network issues or server maintenance, the widget automatically attempts to reconnect. During the reconnection period, users can still interact with existing annotations, but they won't see real-time updates from other users until the connection is reestablished.

Once reconnected, the widget resynchronizes to ensure no updates were missed. This happens transparently without requiring user intervention.

Bandwidth Considerations

WebSocket messages are lightweight and contain only the essential information needed to sync state. Creating a new annotation typically uses less than 1KB of bandwidth. The system also includes intelligent batching to reduce message frequency during high-activity periods.

Your usage metrics in the FastComments dashboard track pubSubMessageCount and pubSubBandwidth so you can monitor real-time sync activity across your sites.

Cross-Tab Synchronization

If a user has the same page open in multiple browser tabs, updates in one tab appear immediately in the other tabs. This works through the same WebSocket sync mechanism and doesn't require any additional configuration.

Security

WebSocket messages are transmitted over secure connections (WSS) and include tenant validation to ensure users only receive updates for conversations they're authorized to see. The server validates all operations before broadcasting them to prevent unauthorized access or manipulation.

Got Questions?

That's it for FastComments Collab Chat! If you have any questions, need help with implementation, or have feature suggestions, please let us know below or reach out to our support team.

For live examples, check out Govscent.org which uses Collab Chat in production.