Skip to content
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

Create extension script event #204

Closed
wants to merge 2 commits into from
Closed

Create extension script event #204

wants to merge 2 commits into from

Conversation

AshimeeAlt
Copy link

@AshimeeAlt AshimeeAlt commented Apr 11, 2024

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
Copy link
Member

Elaborate what this does

@AshimeeAlt
Copy link
Author

AshimeeAlt commented Apr 11, 2024

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
Copy link
Member

Describe what you actually want this for because this seems uselesss

@GarboMuffin
Copy link
Member

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

@AshimeeAlt
Copy link
Author

Describe what you actually want this for because this seems uselesss

ok done

@FurryR
Copy link

FurryR commented Apr 27, 2024

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
Copy link
Author

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
Copy link
Member

GarboMuffin commented May 9, 2024

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
Copy link
Member

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

@AshimeeAlt
Copy link
Author

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

@AshimeeAlt AshimeeAlt closed this May 9, 2024
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.

4 participants