Skip to content

feat: Remove script element immediately in injectScript #1761

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ion1
Copy link

@ion1 ion1 commented Jun 19, 2025

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

@ion1 ion1 requested review from aklinker1 and Timeraa as code owners June 19, 2025 13:23
Copy link

netlify bot commented Jun 19, 2025

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit 41833c6
🔍 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...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Member

@aklinker1 aklinker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, OK nice. If it works, it works! I just noticed your series of PRs... Might re-open the one I closed.

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.
@ion1
Copy link
Author

ion1 commented Aug 3, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants