-
Notifications
You must be signed in to change notification settings - Fork 4k
[feat] Add Python API for st.html unsafe_allow_javascript #12917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
✅ PR preview is ready!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request adds a new parameter unsafe_allow_javascript to the st.html API, allowing users to opt-in to executing JavaScript in HTML content. By default, JavaScript execution is disabled (False) for security reasons.
Key Changes:
- Added
unsafe_allow_javascriptboolean parameter to thehtml()method with default valueFalse - Updated documentation to reflect that JavaScript is now ignored by default and can be enabled via the new parameter
- The parameter is set on the protobuf message and passed through both standard and event container rendering paths
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/streamlit/elements/html.py | Added the unsafe_allow_javascript parameter to the html() method, updated docstring to document the new behavior, and set the parameter on the protobuf message |
| lib/tests/streamlit/elements/html_test.py | Added three unit tests covering default behavior (False), explicit True, and style-only HTML with the flag |
Comments suppressed due to low confidence (1)
lib/streamlit/elements/html.py:93
- The docstring is missing documentation for the new
unsafe_allow_javascriptparameter. According to Numpydoc style conventions, all parameters should be documented in the Parameters section.
width : "stretch", "content", or int
The width of the HTML element. This can be one of the following:
- ``"stretch"`` (default): The width of the element matches the
width of the parent container.
- ``"content"``: The width of the element matches the width of its
content, but doesn't exceed the width of the parent container.
- An integer specifying the width in pixels: The element has a
fixed width. If the specified width is greater than the width of
the parent container, the width of the element matches the width
of the parent container.
d6120c1 to
59e9e84
Compare
9ad33c4 to
0ade7e7
Compare
59e9e84 to
73ab06d
Compare
0ade7e7 to
d276838
Compare
d276838 to
89d39c5
Compare
Merge activity
|
89d39c5 to
0dabd56
Compare

Describe your changes
Added a new
unsafe_allow_javascriptparameter tost.html()that allows JavaScript execution when set toTrue. By default, this parameter isFalse, maintaining the current behavior where JavaScript is ignored.Updated the docstring to clarify that JavaScript execution is now possible but disabled by default, with appropriate warnings about using this feature with caution.
GitHub Issue Link (if applicable)
Testing Plan
unsafe_allow_javascript=TrueContribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.