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

Dynamic menu potential bug in sandboxed extension

Open totchi-lagawi opened this issue 1 year ago • 0 comments

Expected Behavior

When loading a sandboxed extension with a defined dynamic menu, the dynamic menu should work as expected.

Actual Behavior

All the blocks in the block panel stack together at the top of the panel (which isn't important, as it is caused by the following problem), and the console throws the error Uncaught TypeError: e[t] is undefined. The problem came from the function _getExtensionMenuItems. It takes as argument argumentObject, and menuItemFunctionName. It tries to access the function with extensionObject[menuItemFunctionName], but when the extension is sandboxed, this does not exist. The function name is correct. Loading the extension in unsandboxed mode works.

Steps to Reproduce

Load the following extension :

class Extension {
    getInfo() {
        return {
            id: "extension",
            name: "Extension",
            blocks: [
                {
                    opcode: "block",
                    blocktype: "command",
                    text: "A block with an argument : [ARG]",
                    arguments: {
                        ARG: {
                            type: "string",
                            menu: "extensionMenu"
                        }
                    }
                }
            ],
            menus: {
                extensionMenu: {
                    items: "extensionMenuFunction"
                }
            }
        }
    }

    block() {
        console.log("Hello world!")
    }

    extensionMenuFunction() {
        return ["Hello", "world", "!"]
    }
}

Scratch.extensions.register(new Extension())

Operating System and Browser

Firefox 131.0.3 (64-bit) - Windows 11 24H2

totchi-lagawi avatar Oct 25 '24 13:10 totchi-lagawi