Hi everyone!
I’ve been working on building an interactive parts diagram (exploded view) inside a Streamlit app, where users can click on a number in a custom HTML/JS iframe and have that number automatically sent to a Streamlit search bar (like a st.text_input). The goal is to make the app usable via an interactive despiece (spare parts selector).
What works so far:
- A basic iframe with HTML buttons is embedded using
components.html(...). - JavaScript sends data using
window.parent.postMessage(...). - From the browser console, I can see the messages arriving correctly:
yaml
CopiarEditar
✅ Enviado ID: 7
✅ Enviado ID: 18
✅ Enviado ID: 27
What is failing:
- On the Python side, Streamlit shows this repeatedly in the browser console:
bash
CopiarEditar
⚠️ Received component message for unregistered ComponentInstance!
{isStreamlitMessage: true, type: 'codigo_seleccionado', value: '18'}
- In the Streamlit app, instead of getting the number inside a variable or callback, I get something like:
python
CopiarEditar
DeltaGenerator(_provided_cursor=LockedCursor(...), _props={'delta_type': 'iframe', ...})
Things I tried:
- postMessage with plain iframe (
components.html(...)) — HTML sends fine, Python doesn’t receive. - Direct DOM injection (modifying Streamlit’s input with JS) — Works, but it feels like a hack and not reliable long term.
- Installed
streamlit-javascriptcomponent:
pip install streamlit-javascriptgives outdated version (0.1.5)- Tried installing latest from GitHub:
bash
CopiarEditar
pip install --upgrade git+https://github.com/thunderbug1/streamlit-javascript.git
- But it fails due to missing frontend build:
pgsql
CopiarEditar
error: [WinError 2] The system cannot find the file specified
Package 'streamlit_javascript.frontend' is absent from the `packages` configuration
My system setup:
- Windows 11 Pro
- Python 3.13
- Streamlit 1.46.1
- Node.js 22.17.1 + npm installed
- Git installed and working
My questions:
- How can I reliably receive
postMessageevents from an iframe in Streamlit without using unsupported hacks? - Is there any internal listener or official pattern for receiving
window.postMessageinside a Streamlit app? - Is
streamlit-javascripta viable option? Can the maintainers provide a working release or clarify if it’s actively maintained?
Any help from the dev team or others who made this work would be greatly appreciated. I think this use case (interactive diagrams sending data into Streamlit) could be valuable to many in the community!
Thanks ![]()
— From Argentina ![]()