🧩 Plasmo Developers�PD
🧩 Plasmo Developers3y ago
14 replies
emil

CSUI; can I reinject?

Alright, I'm pretty beginner at React & Plasmo, so apologize if I mess up some of my terminology here.
My goal is to add custom buttons to the send window in the ChatGPT UI, and it actually worked pretty awesome first-try with Plasmo CSUI. I just exported my component as default and also exported getInlineAnchor(), and now my buttons appear each time I load the site.

The issue is that, every time you change chats in the ChatGPT UI, the the element is replaced with a new one, so whenever I switch chats, my buttons disappear again. They obviously come back when the page refreshes, but refreshing each time is not ideal.
Example video: https://share.cleanshot.com/vd6nQDPD
CleanShot Cloud
Video uploaded to CleanShot Cloud
CleanShot 2023-09-29 at 17.37.09
Solution
AFAIK you can't "reinject" CSUI
Your best bet right now is it to inject the CSUI manually from a regular content script and have a listener (e.g. https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver ) to know when to reinject
The MutationObserver interface provides the ability to watch for changes being made to the DOM tree. It is designed as a replacement for the older Mutation Events feature, which was part of the DOM3 Events specification.
MutationObserver - Web APIs | MDN
Was this page helpful?