How to execute JS after post content has rendered?

I found api.decorateCookedElement, and I see the note about afterAdopt: true, but that doesn’t get where I’m trying to go.

I’m trying to measure the offset of content within the main topic body with getBoundingClientRect, but it’s always zero because it’s never actually on the page yet…

My code works fine when triggered later (manually through the console, or through an event listener on resize or something, so the issue is just the timing).

This can be worked around by getting the offset of the main content wrapper (#topic), but then I have to manually subtract the avatar width in my calculation, which feels like a kludge and potentially will miss some edge cases of where the decorated elements actually end up sitting.

I also checked for plugin-outlets, but didn’t see any that appeared promising, and decorateWidget got my hopes up but also didn’t seem to apply to posts and post content generically.

Is this possible? Is there an event fired to listen for, or option or hook I’m missing?

2 Likes

You could possibly queue this after next runloop, like this.

3 Likes