scratch-vm icon indicating copy to clipboard operation
scratch-vm copied to clipboard

Create extension script event

Open AshimeeAlt opened this issue 1 year ago • 5 comments

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

AshimeeAlt avatar Apr 11 '24 16:04 AshimeeAlt

Elaborate what this does

CubesterYT avatar Apr 11 '24 16:04 CubesterYT

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.

AshimeeAlt avatar Apr 11 '24 16:04 AshimeeAlt

Describe what you actually want this for because this seems uselesss

GarboMuffin avatar Apr 11 '24 18:04 GarboMuffin

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

GarboMuffin avatar Apr 11 '24 18:04 GarboMuffin

Describe what you actually want this for because this seems uselesss

ok done

AshimeeAlt avatar Apr 12 '24 13:04 AshimeeAlt

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.

FurryR avatar Apr 27 '24 14:04 FurryR

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 💀

AshimeeAlt avatar Apr 27 '24 22:04 AshimeeAlt

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 avatar May 09 '24 05:05 GarboMuffin

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

GarboMuffin avatar May 09 '24 05:05 GarboMuffin

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

AshimeeAlt avatar May 09 '24 22:05 AshimeeAlt