feat: Remove script element immediately in injectScript
[!NOTE] The patch series in which each PR builds on top of the previous one: #1761 (you are here), #1762, #1763, #1838, #1765.
In case some of the changes are rejected, I will rebase the subsequent PRs on top of main.
Overview
I am trying to minimize any chance of my extension leaving something in the DOM or the window object etc.
A script which fails to load would be left in the DOM. Rather than adding an onerror handler, it seems that the script element can just be removed immediately after being added.
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.
Manual Testing
Just using injectScript normally should suffice. I am working on an extension which uses injectScript. It seems to work fine with this change.
Related Issue
N/A
Deploy Preview for creative-fairy-df92c4 ready!
| Name | Link |
|---|---|
| Latest commit | 41833c644da51d05a0c3baeba2d9877b57d42b14 |
| Latest deploy log | https://app.netlify.com/projects/creative-fairy-df92c4/deploys/688f71034d1ff30008355c99 |
| Deploy Preview | https://deploy-preview-1761--creative-fairy-df92c4.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify project configuration.
Huh, OK nice. If it works, it works! I just noticed your series of PRs... Might re-open the one I closed.
Unless I misunderstand which PR you meant by the one you closed, it was one of the three PRs for the same issue but not the one posted by me.