With the release of @forge/react version 11.0.0, enhancements have been made
to the useConfig hook to improve performance in macro config apps when receiving configuration value changes.
Confluence macro config apps relying on the useProductContext
hook or view.getContext() need to
transition to the useConfig hook before upgrading to
@forge/react version 11.0.0 or higher in order to properly access the latest values after the configuration updates.
Confluence macro config apps using the useConfig hook
should upgrade to @forge/react version 11.0.0 for improved performance.
The macro module inserts dynamic content into the user interface via an editor. Editor macros are
only compatible with the Atlassian editor. All cloud sites use the Atlassian editor by default.
The macro module works in Confluence, where the macro is inserted by typing / and selecting
from the quick insert menu of the editor. The macro module is implemented by a Forge function.
On apps that use Custom UI, module content is displayed inside a special Forge iframe which has the sandbox attribute configured. This means that HTML links (for example, <a href="https://domain.tld/path">...</a>) in this iframe won't be clickable. To make them clickable, use the router.navigate API from the @forge/bridge package.

1 2modules {} └─ macro [] ├─ key (string) [Mandatory] ├─ resource (string) [Mandatory] ├─ render (string) [Optional] ├─ resolver {} [Optional] ├─ viewportSize (string) [Optional] ├─ title (string | i18n) [Mandatory] ├─ icon (string) [Optional] ├─ categories (string[]) [Optional] ├─ unlicesedAccess (List<string>) [Optional] ├─ description (string | i18n) [Optional] ├─ hidden (boolean) [Optional] └─ config (boolean | {} | config object) [Optional] ├─ icon (string) [Optional] ├─ title (string | i18n) [Optional] ├─ resource (string) [Mandatory] ├─ render (string) [Optional] ├─ viewportSize (string) [Optional] └─ openOnInsert (boolean) [Optional] ├─ adfExport {} [Optional] ├─ layout (string) [Optional] └─ autoConvert [] [Optional] └─ matchers [] [Mandatory] └─ pattern (string) [Mandatory] resources [] ├─ key (string) [Mandatory] └─ path (string) [Mandatory]Properties
Property Type Required Description key
stringYes A key for the module, which other modules can refer to. Must be unique within the manifest.
Regex:
^[a-zA-Z0-9_-]+$resourcestringIf using Custom UI or modern versions of UI Kit The key of a static resourcesentry that your module will display. See resources for more details.render'native'If using modern versions of UI Kit Indicates the module uses UI Kit. resolver{ function: string }or{ endpoint: string }Set the
functionproperty if you are using a hostedfunctionmodule for your resolver.Set the
endpointproperty if you are using Forge Remote to integrate with a remote back end.viewportSize'small','medium','large'or'xlarge'Use
viewportSizeto pre-reserve the height in the editor before the app loads. Setting this prop disables auto-resizing. This is only supported for the main macro in Custom UI apps.titlestringori18n objectYes The title of the macro. In Confluence, this is displayed in the editor.
The
i18n objectallows for translation. See i18n object.iconstringThe icon displayed next to the
title.
For Custom UI and UI Kit apps, the
iconproperty accepts a relative path from a declared resource. Alternatively, you can also use an absolute URL to a self-hosted icon. See Icons for more information.If no icon is provided, or if there's an issue preventing the icon from loading, a generic app icon will be displayed.
categoriesstring[]The categories of the macro. In Confluence, this is used for categorisation in the macro browser.
formattingconfluence-contentmediavisualsnavigationexternal-contentcommunicationreportingadmindevelopmentdescriptionstringori18n objectThe description of the macro. In Confluence, this is displayed in the editor.
The
i18n objectallows for translation. See i18n object.hiddenbooleanDefaults to
false. When set totrue, hides the macro from the quick insert menu and macro browser in Confluence. This prevents users from inserting new instances of the macro through these interfaces.Existing macros on pages continue to render normally, even when this property is set to
true.configboolean,{ function: string },{ openOnInsert: boolean }orconfig objectSet
configtotrueif you are using classic macro configuration without needingopenOnInsert.Set
configwith theopenOnInsertproperty if you are using classic macro configuration and need theopenOnInsertfeature.openOnInsertdefaults to false.Set
configto the config object if you are using a custom macro configuration.
config.iconstringThe icon displayed next to the title in the custom config modal.
For Custom UI and UI Kit apps, the
iconproperty accepts a relative path from a declared resource. Alternatively, you can also use an absolute URL to a self-hosted icon. See Icons for more information.If no icon is provided, or if there's an issue preventing the icon from loading, a generic app icon will be displayed.
config.titlestringori18n objectA title for the config. If the viewport size is fullscreen*, then the title rendered in the modal header will be this title.config.resourcestringRequired if using Custom UI or the latest version of UI Kit. A reference to the static resourcesentry that your context menu app wants to display. See resources for more details.config.render'native'Yes for UI Kit Indicates the module uses UI Kit. config.viewportSize'small','medium','large','xlarge','max'or'fullscreen'The display size of resource. Can only be set if the module is using theresourceproperty. Remove this property to enable automatic resizing of the module. Forfullscreenviewports, theconfig.titleandconfig.iconwill be displayed in the header. Supported in both UI Kit and Custom UI.config.openOnInsertbooleanDefaults to falsefor classic configuration, defaults totruefor custom configuration. An optional configuration to control if the classic configuration sidepanel or the custom configuration modal is automatically opened when first inserted.adfExport{ function: string }Defines how your macro appears when a Confluence page is exported.
Contains a
functionproperty which references afunctionmodule that returns the macro content in Atlassian document format.The specified function can consume the
exportTypedirectly from the function's payload in order to specify different views per export type. TheexportTypecan be one ofword, orother. See this tutorial for more information.The
adfExportfunction is invoked once per macro instance during export operations. Pages with many macro instances can trigger a large number of invocations in a single export, potentially causing rate limiting and performance issues. Consider minimizing backend work within the function and informing customers about potential limitations when using many macros on pages that will be exported.layout'block','inline'or'bodied'
'block'type is used by default.
'inline'shows the element inline with existing text.
- For UI Kit apps, inline macros dynamically resize to wrap the content.
- Custom UI inline macros have a minimum rendered width of approximately 300px due to the browser's default iframe sizing. To allow your macro to render at a smaller width, set
width: fit-contenton thebodyelement of your Custom UI app's HTML. See Notes on layout and sizing for details.
'bodied'sets the macro to have a rich text body.
- This allows users to insert and edit rich content (such as images and tables) within the macro using the Confluence editor, and allows your app to insert a body using a custom editor.
- Please see the link to the tutorial here.
autoConvertautoConvert objectInserts a macro into the editor when a recognised URL is pasted in by the user. See Macro autoconvert. autoConvert.matchers[matcher, ...]Yes, if using autoConvertThe list of patterns that define what URLs should be matched. autoConvert.matchers.patternstringYes, if using autoConvertA string that defines a specific URL pattern to be matched, using wildcards for variable parts of the URL, such as unique IDs.
- Use multiple wildcards to match multiple sub-paths. Do not include all sub-paths with a single wildcard.
- Ensure URLs do not contain whitespace unless it is URL encoded.
- Wildcards cannot be used in place of a protocol. Custom URL Schemes are supported See examples
- Maximum length of the pattern is 1024 characters.
emitsReadyEventboolean No Defaults to false. An optional configuration to notify Confluence that the macro will send aemitReadyEventwhen it has completed loading and is ready for export or further processing. This should be used withview.emitReadyEvent(). See the view bridge function for more information.unlicensedAccessList<string> A list of unlicensed user types that can access this module. Valid values are: unlicensed(Guests Users), andanonymous. For more information, see Access to Forge apps for unlicensed Confluence users.i18n object
Key Type Required Description i18nstringYes A key referencing a translated string in the translation files. For more details, see Translations. Dynamic module (Preview)
This module can also be declared as a dynamic module. However, this capability is currently available as a Forge preview feature.
For more details, see Dynamic Modules.
When you register a dynamic
macromodule, thedataobject uses the same properties as a staticmacromodule in the manifest. The modulekeyis generated server-side and returned in the create response; for updates, supply it in the URL path.Code examples
The following examples show Dynamic Module implementations specific to this module. For more detailed information about the API used in these examples (including error handling information), see Dynamic Modules API.
Create a dynamic macro module
ForgeNode.js1 2import { asApp } from "@forge/api"; const payload = { "type": "macro", "data": { "resolver": { "function": "resolver" }, "resource": "main", "render": "native", "title": "Dynamic macro", "description": "A macro registered with the Dynamic Modules API", "autoConvert": { "matchers": [ { "pattern": "https://www.example.com/*/about" } ] } } } const response = await asApp().requestAtlassian(`/forge/installation/v2/dynamic/module/`, { headers: { 'Content-Type': 'application/json' }, method: 'POST', body: JSON.stringify(payload), }); const body = await response.text(); console.log(`Response: ${response.status} ${body}`);Update a dynamic macro module
ForgeNode.js1 2import { asApp } from "@forge/api"; const key = "macro-dynamic"; const payload = { "type": "macro", "data": { "resolver": { "function": "resolver" }, "resource": "main", "render": "native", "title": "Updated dynamic macro", "description": "A macro updated with the Dynamic Modules API", "autoConvert": { "matchers": [ { "pattern": "https://www.example.com/*/about" }, { "pattern": "https://www.example.com/*/music" } ] } } } const response = await asApp().requestAtlassian(`/forge/installation/v2/dynamic/module/${key}`, { headers: { 'Content-Type': 'application/json' }, method: 'PUT', body: JSON.stringify(payload) }); const body = await response.text(); console.log(`Response: ${response.status} ${body}`);When you update the URL patterns for a dynamic macro module's autoconvert matchers, you may need to leave the Confluence editor, perform a hard refresh on the Confluence page view, and then re-open the editor before the updated patterns are applied.
Extension context
UI Kit and Custom UI
Property Type Description typestringThe type of the module ( macro).content.idstringA string that represents the unique identifier of the contentobject.content.type"page","blogpost"or"space"A string that represents the type of the contentobject.content.subtypestringornullA string that represents the subtype of the contentobject.nullis returned ifsubtypedoes not apply.space.idstringA string that represents the unique identifier of the spaceobject.space.keystringA string that represents the unique key of the spaceobject.isEditingbooleanIndicates whether the macro is opened in the editor or not. referencesReferenceEntity[] An array of reference entities (if any). Reference entities are a list of any other ADF nodes on the page that are referenced by this macro. configobjectThe configuration parameters saved in this macro. macro.bodyADF document The rich text body of the macro. Available for layout: bodiedmacros only.autoConvertLinkstringThe link pasted by a user that has matched an AutoConvert app. template.idstringA string that represents the unique identifier of the template. This value is only available when the macro is in a saved template. Macro autoconvert
Macro autoconvert allows your app to automatically insert a macro into the editor when a user pastes a recognized URL. This is achieved by defining URL patterns in the manifest using the
matchersproperty. Thesematchersare registered in the editor when the app is installed.Example
1 2modules: macro: - key: autoconvert-app resource: main render: native resolver: function: resolver title: Forge app for autoconvert description: Example for autoconvert manifest autoConvert: matchers: - pattern: https://www.example.com/*/about - pattern: https://www.example.com/*/music - pattern: https://*.example.com/*/movies/* - pattern: https://example.com/gifs/*/ - pattern: http://*.example.com/media/*/.gif - pattern: customScheme:\\example:custom - pattern: customScheme:example:* function: - key: resolver handler: index.handler resources: - key: main path: src/frontend/index.jsx app: id: "<your app id>"The URL patterns use wildcards to match parts of the URL that can vary, such as unique IDs. Wildcards are defined using
*.Use a new
*for each segment in the URL you want a wildcard for. For example,https://www.example.com/*will matchhttps://www.example.com/aboutbut will not matchhttps://www.example.com/about/contact. To match this path as well you need to includehttps://www.example.com/*/*as one of yourmatchers.You'll need to define a separate
matcherfor each relevant internet protocol, such ashttpandhttps.Creating custom URL schemes is also supported. For example,
customScheme:*can be used to match any URL that starts with that custom scheme such ascustomScheme:\\example:custom. Any custom schemes will have to be registered on the system they will be used on, such as iOS, Windows or Android. Either:\\or just:can be used as the initial separator in the URL scheme then:thereon.Example patterns
Wildcard path
1 2- "pattern": "https://www.example.com/*/about"Wildcard in subdomain
1 2- "pattern": "https://www.*.example.com/help"Matching wildcard paths
1 2- "pattern": "https://bitbucket.org/*/*/*"Matching custom URL schemes
1 2- "pattern": "customScheme:example:custom" - "pattern": "customScheme:\\example:custom"Matching custom URL scheme wildcard
1 2- "pattern": "customScheme:example:*" - "pattern": "customScheme:\\example:*"When a pasted URL matches a defined pattern, the macro is created in the editor, and the URL is captured and inserted as a parameter into the macro body. This parameter can be accessed using the
autoConvertLinkproperty.Example app: Macro autoconvert for UI Kit
Learn how to configure auto convert in your manifest.yml file, including pattern matching and setting permissions for API calls.
Macro custom configuration
Extension context in the macro editor
There are two additional extension context parameters available when you are in macro configuration editor context.
Parameter Type Details macro.isConfiguringbooleantrueif the currently rendered resource is theconfigresource,falseif it is the macro's default resourcemacro.isInsertingbooleantrueif a new macro is being inserted,falseif an existing macro is being editedOptions for submitting the configuration
This table details the options supported by view.submit() in the context of custom macro configuration.
Parameter Type Required Details Code configConfig payload Yes Sets the config properties of the macro. 1 2view.submit({ config: { param1: "test", param2: [1, 2, 3] } })bodyADF document No Sets the rich text body of the macro. Can only be used with layout: bodiedmacros. 1 2view.submit({ config: {}, body: { type: "doc", version: 1, content: [ // ADF content ] } })keepEditingbooleanNo Defaults to false, which automatically closes the config modal on submit. Set this totrueto keep the modal open. 1 2view.submit({ config: {}, keepEditing: true })Supported config payload format
The
configpayload only supports values that can be serialised to JSON.The following types are allowed on the payload:
undefinedstringnumberbooleanobject(can contain any of the allowed types, including nested objects)array(can contain strings, numbers, booleans, and objects; all items in the array must be of the same type).The following types are not allowed:
- Nested arrays (arrays as direct children of arrays)
null- Any data types that are not serializable to JSON (e.g.
Map,Set, etc.)If you want greater control over the storage format of your configuration, such as being able to store nested arrays and nulls, we recommend serializing your configuration to JSON upfront, and storing it as a string.
Error code guide
This table details the possible error codes that may be thrown by
view.submit():
Error code Details INVALID_PAYLOADThe top-level parameter passed to view.submit()must be an object.INVALID_CONFIGThe configprop provided must be an object that is compliant with the config payload format above.INVALID_EXTENSION_TYPEWhen providing a body, the macro must be a rich text macro (layout: "bodied").INVALID_BODYThe provided bodyis not a valid ADF document node.MACRO_NOT_FOUNDThe macro that you are attempting to update no longer exists. It may have been deleted by another user editing the page. Notes on layout and sizing
Inline macro width (Custom UI)
Custom UI inline macros are rendered inside an
<iframe>. All major browsers apply a default minimum width of 300px to<iframe>elements, which means your inline macro will render at a minimum of approximately 300px wide even if the content inside is smaller.To override this and allow the macro to shrink to fit its content, add the following CSS to your Custom UI app. The recommended approach is to add it in a
<style>tag or an external stylesheet in yourindex.html:1 2<style> body { width: fit-content; } </style>This tells the browser to size the body to its content rather than expanding to the iframe default width. The
fit-contentvalue is supported across all browsers that Forge targets.If you apply these styles using a
styleattribute directly on the<body>element (for example,<body style="width: fit-content">), you must also declare theunsafe-inlinepermission in yourmanifest.yml, as inline styles are blocked by the default Content Security Policy:1 2permissions: content: styles: - "unsafe-inline"Using a
<style>tag or external stylesheet does not require this permission.This limitation only applies to Custom UI apps. UI Kit inline macros automatically resize to wrap their content without any additional configuration.
Tutorials
Rate this page: