Bug 578017

Summary: [Browser][Edge] cannot invoke "evaluate" inside a BrowserFunction
Product: [Eclipse Project] Platform Reporter: Kent Xu <kentxu2007>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P3 CC: akhilm.usapp, andrewle1610, kevin, nikita, niraj.modi
Version: 4.22   
Target Milestone: ---   
Hardware: PC   
OS: Windows 10   
Whiteboard:
Bug Depends on:    
Bug Blocks: 575660    
Attachments:
Description Flags
simple demo
none
simple html none

Description Kent Xu CLA 2022-01-02 13:00:19 EST
Created attachment 287762 [details]
simple demo

BrowserFunction gets stuck if "evaluate" is invoked inside it. This is only happening after we upgraded to Edge, worked fine on IE11 or OSX (Safari Webkit).
Comment 1 Kent Xu CLA 2022-01-02 13:01:06 EST
Created attachment 287763 [details]
simple html
Comment 2 Niraj Modi CLA 2022-01-07 05:52:28 EST
(In reply to Missing name from comment #0)
> Created attachment 287762 [details]
> simple demo
> 
> BrowserFunction gets stuck if "evaluate" is invoked inside it. This is only
> happening after we upgraded to Edge, worked fine on IE11 or OSX (Safari
> Webkit).

This a known issue with embedded EDGE browser(WebView2 support for SWT).
Limitation of 'evaluate()' method is mentioned in below readme file:
https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/174084/8/bundles/org.eclipse.swt/Readme.WebView2.md#103
Comment 3 Niraj Modi CLA 2022-01-07 05:53:34 EST
Work-around:
- Suggested to use async call, similar to attachment 287762 [details]

Possible alternate:
- by exposing the asynchronous `evaluate()` method
Comment 4 andrew le CLA 2022-02-25 14:30:46 EST
Hi, any update on this issue? Unfortunately, async can't be used in my scenario as the value is needed in order for the application to continue.
Comment 5 Akhil Kumar Mandava CLA 2022-04-04 12:34:20 EDT
Hi @Niraj Modi, is it possible to do a synchrounous operation for browser.evaluate()? I need to use the result from evaluate in the next line of program . 

I have a scenario something like this : 

class TestNamespacesFunction extends BrowserFunction
{
    private static final String FUNCTION_NAME = "createNamespaces"; //$NON-NLS-1$
    Browser browser;
    Object test;

    WrapNamespacesFunction(Browser browser)
    {
        super(browser, FUNCTION_NAME);
        this.browser = browser;
    }

    @Override
    public Object function(Object[] arguments)
    {
        test = null;
        final String IS_UNDEFINED_SCRIPT = "return typeof({0}) != ''function'';"; //$NON-NLS-1$
        test = browser.evaluate(MessageFormat.format(IS_UNDEFINED_SCRIPT, "createNamespaces"));

        return test;
    }

}

Appreciate any thoughts ?