[Advice needed] feat: Have injectScript return the return value of the script
[!NOTE] The patch series in which each PR builds on top of the previous one: #1761, #1762, #1763, #1838, #1765 (you are here).
In case some of the changes are rejected, I will rebase the subsequent PRs on top of main.
Overview
A sketch for having injectScript return the result value from the script. The code works, but it currently has changes to virtual/unlisted-script-entrypoint.ts that only work with injectScript while being broken with the browser.scripting API.
I would like to get feedback on how you would like that to be resolved. Some options I can think of:
- Have the entrypoint detect whether it is being run from
injectScriptorexecuteScript. I do not know how to achieve that reliably.document.currentScriptcan be overridden by the web page usingObject.defineProperty, so its value might not be a reliable way to determine that. - Build separate entrypoints depending on whether the script is injected using
injectScriptorexecuteScript.
Manual Testing
Use injectScript on a script which either returns a value or throws an exception; see that injectScript returns the value or rethrows the exception.
Related Issue
#1754 proposes having a way to pass an UnlistedScriptDefinition rather than the filename to injectScript. If something like that was implemented, the type of the return value of injectScript could be based on the type of main within the UnlistedScriptDefinition.
Deploy Preview for creative-fairy-df92c4 ready!
| Name | Link |
|---|---|
| Latest commit | 3aebc7c1292f8ff62e5dd5f7bc8729f10db10e12 |
| Latest deploy log | https://app.netlify.com/projects/creative-fairy-df92c4/deploys/688fcde20acd6c0008bab271 |
| Deploy Preview | https://deploy-preview-1765--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.