Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Make ExecuteScriptAsync visible from WebviewBridge #28

@TamaBaka

Description

@TamaBaka

There is an interesting segment of code in SpiderEye.Bridge.WebviewBridge:

        public async Task InvokeAsync(string id, object data)
        {
            string script = GetInvokeScript(id, data);
            string? resultJson = await Application.Invoke(() => Webview.ExecuteScriptAsync(script));
            ResolveEventResult(id, resultJson);
        }

I'm actually using webview for automation instead of creating an interactable custom webpage so I found the ExecuteScriptAsync feature useful on the Windows Webview. Except I was trying to port my code to a Raspberry Pi and Webview currently doesn't work on Linux.

Given the code segment above, I think it might be possible to reproduce that behavior here if we could directly inject a custom javascript string instead of searching for a pre-registered function. I.e. skip the GetInvokeScript step and the ResolveEventResult step and just return resultJson directly.

Is this not done because the intent of the bridge was to work with well-defined endpoints? Or is it because calling ExecuteScriptAsync directly is inherently unstable and creates all sorts of unpredictable side effects? Did I happen to miss a function that actually does what I'm requesting already?

Bear in mind that I don't control the endpoint, so I can't insert custom code into the destination webpage. And I'm not desperate enough to encapsulate the endpoint into an iFrame just so I can embed tools in the parent container to manipulate whatever's in the iFrame.

That being said, here's an example of my code when I directly used Webview2.

                        var script = $@"
                                document.querySelector(""input[name='USER']"").value = ""{ kvp[0] }"";
                                document.querySelector(""input[name='PASSWORD']"").value = ""{ kvp[1] }"";
                                document.querySelector(""#logon_button"").click();
                        ";

                        await signInView.ExecuteScriptAsync(script);

Set a user, set a password, then click a specific button. Wait for page loaded event to execute further actions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions