TurboWarp / scratch-vm

Scratch VM with a JIT compiler and more features
https://turbowarp.org/
Mozilla Public License 2.0
75 stars 72 forks source link

Create extension script event #204

Closed AshimeeAlt closed 5 months ago

AshimeeAlt commented 6 months ago

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 :(

CubesterYT commented 6 months ago

Elaborate what this does

AshimeeAlt commented 6 months ago

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.

GarboMuffin commented 6 months ago

Describe what you actually want this for because this seems uselesss

GarboMuffin commented 6 months ago

"Easier access to loading stuff." Is not a justification. Post some actual code you would write using this api.

AshimeeAlt commented 6 months ago

Describe what you actually want this for because this seems uselesss

ok done

FurryR commented 5 months ago

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.

AshimeeAlt commented 5 months ago

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.

yes and that it not what i want 💀

GarboMuffin commented 5 months ago

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?

GarboMuffin commented 5 months ago

You mention "I have actually needed this before so its not useless" -- when??

AshimeeAlt commented 5 months ago

im sorry for making this pr, it was a waste of everyone who was involved's time.