Skip to content

fix: Make injectScript wait until loaded #1763

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 3 commits into
base: main
Choose a base branch
from

Conversation

ion1
Copy link

@ion1 ion1 commented Jun 19, 2025

Note

This PR builds on top of #1761 and #1762 at the moment. In case either of them are not accepted, I will rebase this on top of main.

Overview

The documentation states:

injectScript returns a promise, that when resolved, means the script has been evaluated by the browser and you can start communicating with it.

However, currently injectScript returns as soon as the script element has been added to the DOM.

This PR makes injectScript behave according to the documentation.

Manual Testing

Invoke injectScript and observe that it will wait until the script has loaded.

Related Issue

N/A

ion1 added 2 commits June 19, 2025 16:16
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.
It enables the manipulation 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 via
`document.currentScript`).
@ion1 ion1 requested review from aklinker1 and Timeraa as code owners June 19, 2025 16:33
Copy link

netlify bot commented Jun 19, 2025

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit 5af7647
🔍 Latest deploy log https://app.netlify.com/projects/creative-fairy-df92c4/deploys/6855729729c4d70008966bef
😎 Deploy Preview https://deploy-preview-1763--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.

@ion1 ion1 changed the title feat: Add waitUntilLoaded to injectScript fix: Make injectScript wait until loaded Jun 19, 2025
@ion1 ion1 force-pushed the inject-script-wait branch from 4617287 to de58942 Compare June 19, 2025 18:59
The documentation states:

> `injectScript` returns a promise, that when resolved, means the script
> has been evaluated by the browser and you can start communicating with
> it.

However, currently `injectScript` returns as soon as the `script`
element has been added to the DOM.

Make `injectScript` behave according to the documentation.
@ion1 ion1 force-pushed the inject-script-wait branch from de58942 to 5af7647 Compare June 20, 2025 14:39
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.

1 participant