-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
aklinker1
left a comment
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 |
modifyScript option to injectScript
aklinker1
left a comment
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.
Getting all your PRs merged...
@wxt-dev/analytics
@wxt-dev/auto-icons
@wxt-dev/browser
@wxt-dev/i18n
@wxt-dev/module-react
@wxt-dev/module-solid
@wxt-dev/module-svelte
@wxt-dev/module-vue
@wxt-dev/runner
@wxt-dev/storage
@wxt-dev/unocss
@wxt-dev/webextension-polyfill
wxt
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1762 +/- ##
==========================================
- Coverage 76.76% 76.63% -0.13%
==========================================
Files 113 113
Lines 3025 3026 +1
Branches 686 686
==========================================
- Hits 2322 2319 -3
- Misses 622 624 +2
- Partials 81 83 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for helping make WXT better! |
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
modifyScriptenables 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
datasetproperty (which can be accessed by the script viadocument.currentScript), as shown in the example:It can also be used to change
script.async/script.deferor to set up event listeners for communication through thescriptelement.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.