Integrate Custom Webapp for Content Insertion as External Type Region
Introduction
The Custom Webapp for Content Insertion enables developers to integrate custom web applications as dialogs within Quark Author. This feature allows external webapps to communicate bidirectionally with the editor, enabling custom user interfaces that can interact with document content, insert elements onto the canvas, and access editor context to achieve a wide range of use cases.
Below is the screenshot of sample Custom Webapp integrated with Quark Author to interact with canvas:

Below is the screenshot showing content inserted in the canvas (wrapped inside an external type region) by the webapp:

Key Capabilities
Dialog Integration: Load external webapps into customizable dialogs within Quark Author.
Bidirectional Communication: Exchange messages between the webapp and editor using a secure event-based protocol.
Content Insertion: Insert customized/use case-driven content into the document from external webapps as a region (type: external).
Selection Context: Receive real-time editor selection changes and metadata.
Note: You can also mark this external region as a read-only part of the document to achieve data-driven content population uses cases.
Authentication Support: Securely fetch authentication tokens for external API calls.
Callback System: Execute validation and transformation logic before content insertion.
Configuring External Webapp in Application Service
Create or update the external webapp configuration file:
- This step is mandatory for registering the external webapp with Quark Author/ Workspace
- This configuration goes in the applicationservice directory on S3
Location: applicationservice/conf/external-webapp-config.json
Sample Configuration
{
"version": "0.1",
"configs": [
{
"webAppId": "external-content-insertion",
"frameUrl": http://localhost:4202/,
"dialogConfig": {
"height": 500,
"width": 700,
"draggable": true,
"resizable": true,
"closeConfig": {
"showCloseButton": true,
"showConfirmationOnClose": true,
"confirmationMessage": "Close Dialog?"
}
},
"externalWebAppAuthConfig": {
"httpMethod": "POST",
"authTokenUrl": https://your-auth-server.com/example/token,
"requestBody": {
"client_id": "${YOUR_AUTH_SERVER_REALM_CLIENT_ID_ENV_VAR}",
"client_secret": "${YOUR_AUTH_SERVER_REALM_CLIENT_SECRET_ENV_VAR}",
"grant_type": "grant_type_value"
}
}
}
]
}
Download Sample: External Webapp Config
Quark Author Configuration (in case of triggering the external webapp from toolbar ribbon)
Folder Structure
Create the following folder structure under the ‘qaservice’ directory on S3:
qaservice/
└── ext/
└── feature/
└── content-insertion-extension/
└── content-insertion-extension/Adding the Icon
Place an icon (e.g., ‘icon.png’) in the ‘content-insertion-extension’ folder:
qaservice/
└── ext/
└── feature/
└── content-insertion-extension/
└── content-insertion-extension/
└── icon.pngThe icon name can be customized but must match the value of ‘iconUrl’ in the ‘manifest.json’ file.
Create the manifest.json file
Place an icon (e.g., ‘icon.png’) in the ‘content-insertion-extension’ folder:
qaservice/
└── ext/
└── feature/
└── content-insertion-extension/
└── manifest.jsonManifest file structure:
{
"version": "0.0.1",
"modules": [
{
"type": "qa-canvas-plugin",
"displayName": "DISPLAY_NAME_OF_BUTTON",
"name": "PLUGIN_NAME",
"iconUrl": "ICON_NAME",
"bundle": "PLUGIN_BUNDLE_PATH"
}
]
}
Configuring Parameters:
type: Must be “qa-canvas-plugin” for toolbar button plugins
displayName: Label shown on the toolbar button
name: Unique identifier for the plugin
iconUrl: Path to the icon file (relative or absolute)
bundle: Path to the plugin JavaScript file
To download sample, click here.
Configuring qa-config.json
Add the plugin and toolbar button to the content type configuration:
{
"toolbar": {
"mainTabs": [
{
"id": "home",
"label": "Home",
"type": "main",
"mode": "any",
"items": [
"ParaStyles",
"InlineStyles",
"Bold",
"Italic",
"Underline",
"Strike",
"Subscript",
"Superscript",
"BulletedList",
"NumberedList",
"Indent",
"Outdent",
"Find",
"viewxml",
"external-content-insertion-btn"
// add the toolbar button here or in any other tab as needed
]
}
// ... other tabs
]
},
"extensions": [
"content-insertion-extension"
]
// add the plugin name here to load the Manifest and register the plugin
}
Note: Restart qaservice after making these changes.
Event Protocol
All communication between the external webapp and Quark Author happens via the window.postMessage API. The webapp receives events from the editor and sends events back using this mechanism.
Event Types
Events Sent by Quark Author (Editor → Webapp)
1. SELECTION_CHANGE
Sent automatically when the user’s selection changes in the editor (debounced 200ms).
Payload
Example Payload: Selection Change event payload. To download sample, click here.
{
"webAppId": "your-webapp-id",
// same as configured in external-webapp-config.json
"event": "SELECTION_CHANGE",
"assetId": "01234",
"contentType": "Smart Document",
"userId": "1",
"versionInfo": {
"minorVersion": "0",
"majorVersion": "1",
"brachId": "0"
},
"targetElementType": "callout",
"targetElement": "region",
"content": "Selected HTML content",
"meta": {}
// metaInfoJson, for better readability refer to `Selection Change event payload` above.
}
2. FETCH_TOKEN_STATUS
Response to TOKEN_REQUESTED event with authentication token or error.
Success Payload
{
"webAppId": "external-content-insertion",
"event": "FETCH_TOKEN_STATUS",
"status": "SUCCESS",
"auxData": {
// can vary based on external API
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600
}
}
Failure Payload
{
"webAppId": "external-content-insertion",
"event": "FETCH_TOKEN_STATUS",
"status": "FAILURE",
"error": "Error Object"
}
3. INSERT_CONTENT_STATUS
Confirmation after processing INSERT_CONTENT request.
Success Payload
{
"webAppId": "external-content-insertion",
"event": "INSERT_CONTENT_STATUS",
"status": "SUCCESS",
"content": "inserted content
"
// the content inserted by the external webapp
}
Failure Payload
{
"webAppId": "external-content-insertion",
"event": "INSERT_CONTENT_STATUS",
"status": "FAILURE",
"error": "Error Object"
}
Events Sent by External Webapp (Webapp → Editor)
1. TOKEN_REQUESTED
Request authentication token from the configured external API.
Payload
window.parent.postMessage(
{
event: "TOKEN_REQUESTED",
webAppId: "external-content-insertion", // must match the configured webAppId
},
"*"
);
Note: The webapp must be loaded in the dialog at least once before requesting tokens.
2. INSERT_CONTENT
Request the editor to insert content at the current cursor position.
Payload
window.parent.postMessage(
{
event: "INSERT_CONTENT",
webAppId: "external-content-insertion", // must match the configured webAppId
content: "<p>Content to insert</p>", // can be HTML/JSON/XML (Will require transformation callback in the plugin to handle non-HTML formats)
assetId: "asset-123",
versionInfo: {
minorVersion: "0",
majorVersion: "1",
brachId: "0",
},
},
"*"
);
Parameters
content: The HTML content to insert (required)
contentType: Type of content (default: “html”)
assetId: Unique identifier for the asset (optional)
versionInfo: Version information for the asset (optional)
3. CLOSE_DIALOG
Request to close the external webapp dialog.
Payload
window.parent.postMessage(
{
type: "CLOSE_DIALOG",
data: {
dialogId: "33258cc0-d0f1-11f0-8e59-e3ecfc46785b",
},
},
"*"
);
Event Status Types
All status responses use one of two values:
SUCCESS: Operation completed successfully
FAILURE: Operation failed (check error field for details)
Implementation Examples
This is a simple example demonstrating how to implement an external webapp that interacts with Quark Author using the defined event protocol.
Simple External Content Insertion Webapp
For a complete example of a simple external webapp that demonstrates the event protocol, see: Sample Webapp Code.
Complete Custom Plugin with Content Transformation
For a complete custom plugin implementation that transforms content from external webapp into Quark-compatible HTML, see: plugin.js.
Key Features:
Content Format Detection: Automatically detects JSON or XML content (use create document service APIs for getting the supported json and xml)
Format Conversion: Converts Smart JSON → XML → Smart HTML
Applicable Metadata: Applicable meta can be passed from the plugin:
- Error Handling: Returns false to cancel insertion if transformation fails
- Validation: Uses helper functions to validate content format before processing
editorInstance.addCommand(contentInsertionExtension, {
exec: async () => {
const config = {
applicableMeta: ["keywords", "dates"],
};
qaExternalWebAppBridge.showExternalWebappDialog(externalWebAppId, config);
},
});
Troubleshooting
Dialog Not Appearing
Check plugin configuration:
- Verify bundle: “externalContentPlugin” is set correctly
- Ensure webAppId matches the external webapp config
Check external webapp config:
- Verify file location: applicationservice/conf/external-webapp-config.json
- Validate JSON syntax
- Ensure webAppId matches plugin configuration
Check qaservice:
- Restart qaservice after configuration changes
- Check logs for configuration loading errors
Messages Not Being Received
Check origin validation:
- Ensure webapp is served from the exact URL specified in frameUrl
- Check browser console for CORS errors
Check event listeners:
- Verify window.addEventListener(“message”, …) is registered
- Check that event handler is not throwing errors
Check message format:
- Ensure event property is set correctly
- Verify all required fields are present
Content Not Inserting
Check callback returns:
- If using beforeContentInsertion callback, ensure it returns truthy value
- Check console for callback errors
Check content format:
- Test authTokenUrl directly to verify it’s accessible
- Verify httpMethod, requestHeaders, and requestBody are correct
Check INSERT_CONTENT_STATUS:
- Listen for status response to identify specific errors.
Review app.component.ts and insert-region.component.ts in the Sample webapp
- Ensure that the receiveMessage method in both files validates the message origin by checking event.origin against your own approved domain.
Token Fetch Failing
Check origin validation:
- Ensure all ${qpp.*} variables are set in qaservice environment
- Verify variable names match exactly (case-sensitive)
Check event listeners:
- Test authTokenUrl directly to verify it’s accessible
- Verify httpMethod, requestHeaders, and requestBody are correct
Check message format:
- Examine error for specific failure reason
- Check applicationservice logs for detailed error information