Getting edit representation of the page during a live Confluence Cloud edit session

I’d like to be able to get the current edit mode contents of the current page during my cloud dynamic macro editing session to find copied/pasted versions of the same macro on the page that were inserted within the same edit session.

The REST APIs can return the edit representation before the current edit session, but I don’t see a way to get the live current edit session contents.

The usage case here is that user edits a new page, adds one of our dynamic macros. They then, without updating and saving the page, copy and paste the macro instance on the new page and then open our custom editor for one of the instances.

At save time for the instance, I’d like to be able to detect that there are copies (since they may share attachment data) and give the user some messaging about changes to this instance affecting the others.

I can do this if the other copied instances were already on the page before going into the edit session, but not on the live edit session.

There is currently no API to collect the entire page during an edit session. Feel free to raise an improvement request here: Confluence Ecosystem (Moved: go.atlassian.com/ce-move) - Issues - Ecosystem Jira

I assume you want to make sure that copies of your macro both refer to the same related data, or share the same configuration. The only way I can think of doing this is responding to a page save event, scanning the page storage format at this point, and resolving the conflicts with another update from your add-on.

Our specific use case is giving some user feedback about shared attachments that are created by our macro instances and referenced/rendered via macro parameters. We’re able to easily detect the cross-page duplicate case, or duplicate case on a page that has multiple instances before starting the page edit session, but not a brand new page with copied/pasted macro instances. Not a huge deal, but would be a “nice to have”.