I am developing a custom extension (let's call it "ImageEditor") for EspoCRM and I'm struggling to inject a custom "Edit" button into the attachment preview blocks.
My setup:
What I've done so far:
The problem: Even though the script runs and the HTML is visible in the Inspector, jQuery selectors like $('.attachment-preview') or $('a[data-id]') often return length: 0 in the script context, or the injection via .after() / .append() simply doesn't manifest in the DOM.
Additionally, I've encountered CSP (Content Security Policy) blocks when trying to load the script as a standard scriptList entry, so I moved it to afterAppRunList.
Questions:
Any guidance on the correct "Entry Point" for DOM manipulation in the record detail view would be greatly appreciated!
My setup:
- EspoCRM version: 9.x
- Goal: Add a button to .attachment-preview to open a custom modal for image editing.
What I've done so far:
- Registered the script via afterAppRunList in metadata/app/client.json.
- The script successfully logs to the console, so it is being loaded.
- I am using an setInterval loop to scan for .attachment-block-preview or a[data-action="showImagePreview"].
The problem: Even though the script runs and the HTML is visible in the Inspector, jQuery selectors like $('.attachment-preview') or $('a[data-id]') often return length: 0 in the script context, or the injection via .after() / .append() simply doesn't manifest in the DOM.
Additionally, I've encountered CSP (Content Security Policy) blocks when trying to load the script as a standard scriptList entry, so I moved it to afterAppRunList.
Questions:
- Is there a recommended "Espo-way" to extend the Attachment or Image field views specifically to add custom actions/buttons without overwriting the entire .tpl file?
- How can I ensure my script has access to the DOM after the AJAX-driven fields have finished rendering?
- Are there specific CSP considerations for scripts in client/custom/modules/... that might prevent DOM manipulation even if the script itself executes?
Any guidance on the correct "Entry Point" for DOM manipulation in the record detail view would be greatly appreciated!

Comment