-
-
Notifications
You must be signed in to change notification settings - Fork 360
feat: Add modifyScript option to injectScript #1762
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Looks good, but can we call it modify
instead of manipulate
?
Sure, I'll update my patch series in a bit. |
Everything seems to work: the script is executed; onload, onerror handlers do the right thing; document.currentScript invoked by the script returns the detached script element.
55c59d4
to
c4f2c2d
Compare
Updated. |
It enables the modification of the script element just before it is added to the DOM. It can be used to e.g. modify `script.async`/`script.defer`, add event listeners to the element, or pass data to the script via `script.dataset` (which can be accessed by the script via `document.currentScript`).
c4f2c2d
to
e040fb5
Compare
I had forgotten to rename one |
Note
The patch series in which each PR builds on top of the previous one: #1761, #1762 (you are here), #1763, #1838, #1765.
In case some of the changes are rejected, I will rebase the subsequent PRs on top of main.
Overview
modifyScript
enables the the modification of the script element just before it is added to the DOM.It can be useful for e.g. passing data to the script via the
dataset
property (which can be accessed by the script viadocument.currentScript
), as shown in the example:It can also be used to change
script.async
/script.defer
or to set up event listeners for communication through thescript
element.Manual Testing
It can be tested as shown in the example above.
Related Issue
#1755 proposes a higher level (and potentially type-checked) API for passing an object to the script.