scratch-vm
scratch-vm copied to clipboard
Create extension script event
idk how garbo wants me to fix the vm missing error.
Resolves
One of my proposed changes in the discord.
Proposed Changes
Emits a event when a extension script is created.
Reason for Changes
I wanted access to be able to modify some script stuff and the loading api so that we can modify it externally but i dont think you would do that so i did this. aso you wanted to see some code so
// simple example that adds a comment to the top of the extension
vm.on('CREATE_EXTENSION_SCRIPT', script => {
if (script.tagName === 'script') {
script.src = `data:application/javascript;base64,${btoa(`// example
${atob(script.substr(script.indexOf(',')))}`)}`
}
});
I have actually needed this before so its not useless
Test Coverage
No test coverage sorry :(
Elaborate what this does
Elaborate what this does
lets us modify the scripts for extensions before they are loaded, ideally we would just be able to access the loading script directly but we cannot.
Describe what you actually want this for because this seems uselesss
"Easier access to loading stuff." Is not a justification. Post some actual code you would write using this api.
Describe what you actually want this for because this seems uselesss
ok done
Do you know that you can actually proxy Scratch API by listening to CREATE_UNSANDBOXED_EXTENSION_API (its newly introduced feature)?
That allows you to patch Scratch.extensions.register to kinda achieve your goal.
Do you know that you can actually proxy Scratch API by listening to
CREATE_UNSANDBOXED_EXTENSION_API(its newly introduced feature)? That allows you to patchScratch.extensions.registerto kinda achieve your goal.
yes and that it not what i want 💀
What can you do with this that you can't do using CREATE_UNSANDBOXED_EXTENSION_API or just modifying global variables directly? "lets us modify the scripts for extensions before they are loaded" is just a means to a goal -- what is that goal? Putting comments at the start of an extension doesn't make sense. I genuinely can't understand what your goal is.
Sandboxed worker patch also won't actually do what you want (next line will overwrite any source changes you made to the iframe) even if we ignore the ESLint error
This API also does not account for extensions loaded from https://... URLs, how would you insert JS at the start of one of those URLs?
You mention "I have actually needed this before so its not useless" -- when??
im sorry for making this pr, it was a waste of everyone who was involved's time.