The HTML returned from the plumber endpoint is for a full HTML page. Would it be possible to have your widget inside an iframe?
javascript - How to set HTML content into an iframe - Stack Overflow suggests that you can set the content of the iframe on your page using the srcdoc
attribute
In 2023, the correct answer to this problem is to use the
srcdoc
attribute of the<iframe>
element. I can be done straight in your HTML file or with javascript:document.getElementById('iframe').srcdoc = "<html><body>Hello world!</body></html>";
So you could continue handle your POST as you currently are, but when you set the content, you'd set the srcdoc
attribute of the iframe on the page.