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

[Edge][BrowserFunction] BrowserFunctions added to window undefined when URL loaded #20

Open
kwinter108 opened this issue Apr 5, 2022 · 3 comments
Assignees
Labels
bug Something isn't working edge Edge Browser Windows Happens on Windows OS

Comments

@kwinter108
Copy link

I have ran into an issue on the 2021-09 release where BrowserFunctions are sometimes undefined in the window when using the Edge browser. This looks to be caused by some sort of race condition that occurs when a Browser has BrowserFunctions registered and its URL is set quickly after it is constructed. When more time is added between the construction of the Browser instance and registering browser functions/setting the URL, the error occurs far less frequently. This issue is unique to Edge as the code works without issue when using IE.

From briefly looking over the code and documented changes, this looks to be related to execute(String script) no longer being synchronous when using the Edge browser implementation. When adding a browser function to the window, createFunction(BrowserFunction function) calls nonBlockingExecute(String script) to execute the JS used to define the browser function in the window. The browser's own implementation of execute(String script) is then called to run the script. This then asynchronously adds the browser function to the window.

It might be possible to correct this by adding an override implementation of createFunction(BrowserFunction function) to Edge.java and using a similar strategy as the Edge evaluate(String script) does to wait for the callback to report completion before continuing.
A good alternative would also be adding support for Window.postMessage() as mentioned in the Potential API addons. With asynchronous options being commonly preferred in web development the synchronous behavior of browser functions will likely become harder to maintain and less desired as time goes on.

@vogella
Copy link
Contributor

vogella commented Apr 5, 2022

@nnemkin worked on browser functions via https://bugs.eclipse.org/bugs/show_bug.cgi?id=573616 Can you check if the latest i-Build still have the issue? https://download.eclipse.org/eclipse/downloads/

@nnemkin
Copy link
Contributor

nnemkin commented Apr 5, 2022

Lars, that bug is GTK specific.

For Edge, the current BrowserFunction injection mechanism is indeed suboptimal. It was inherited from the MSIE implementation, which is a lot less asynchronous. The proper way to inject BrowserFunctions is to use script injection API (AddScriptToExecuteOnDocumentCreated). This API, in theory, guarantees that the injected code runs before any page scripts, although the call itself is asynchronous and might race with page navigation.

Also, Bug 578016 might be the same bug or at least be fixed together with this one.

@nnemkin nnemkin self-assigned this Apr 5, 2022
@nnemkin nnemkin added the bug Something isn't working label Apr 5, 2022
@lshanmug lshanmug added the Windows Happens on Windows OS label Apr 22, 2022
@akurtakov
Copy link
Member

Is this bug still happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working edge Edge Browser Windows Happens on Windows OS
Projects
None yet
Development

No branches or pull requests

6 participants