-
Notifications
You must be signed in to change notification settings - Fork 183
Description
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.