Bug 578016 - [Browser][Edge] BrowserFunction only works in one app shell
Summary: [Browser][Edge] BrowserFunction only works in one app shell
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.22   Edit
Hardware: PC Windows All
: P3 major with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Nikita Nemkin CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 575660
  Show dependency tree
 
Reported: 2022-01-02 12:49 EST by Kent Xu CLA
Modified: 2023-02-03 16:05 EST (History)
8 users (show)

See Also:


Attachments
simple html that invokes a BrowserFunction (747 bytes, text/html)
2022-01-02 12:49 EST, Kent Xu CLA
no flags Details
simple app (2.18 KB, application/octet-stream)
2022-01-02 12:49 EST, Kent Xu CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kent Xu CLA 2022-01-02 12:49:00 EST
Created attachment 287760 [details]
simple html that invokes a BrowserFunction

In this simple example, there are three identical browsers. Each with a html button that sends some dummy data to BrowserFunction. They all work fine.

If I launch a second instance of the same app. The browser and html shows up but no BrowserFunction is ever triggered. 

I first noticed this problem in a more complex app where there are multiple JFace Dialogs showing at the same time, each with an Edge browser. 

This is only a problem in Edge/WebView2 implementation. The same code works on OSX and Windows IE 11 mode.
Comment 1 Kent Xu CLA 2022-01-02 12:49:59 EST
Created attachment 287761 [details]
simple app
Comment 2 Pavlo Khodakivskyi CLA 2022-06-24 15:00:17 EDT
Hi! Expiriencing the same issue. 

Could anybody advice is there any solutions or workaround for that issue?
Comment 3 Christopher Mindus CLA 2022-06-28 10:23:24 EDT
Please try:

browser.getDisplay().asyncExec(()->{
  final File testFile = new 
  File(EdgeBrowserTest.class.getResource("EdgeBrowserTest.html").toURI());
  browser.setUrl(testFile.toURI().toString());
});

instead of calling browser.setUrl(..) directly after registering the BrowserFunction. That seems to cure the problem in our code at least.
Comment 4 matthieu perin CLA 2022-11-04 04:24:38 EDT
Tried the workarround proposed but was not successfull for us :(

Our usage is a browser within a specialized EcoreEditor, we encounter the same bad behavior: first tab work perfect, second open tab start withoyut having any BrowserFunction loaded.
Comment 5 Paul Lubberstedt CLA 2023-02-03 16:05:48 EST
My team managed to get the issue resolved by setting the BrowserFunction inside ProgressAdapter#completed(). See example below (commented out code was before changes):

    public EdgeUpliftBrowserWindow(Shell parent)
    {
//        Browser browser = new Browser(parent, SWT.EDGE);
//        new OpenTestWindow(browser);
//        browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
//        browser.setUrl(HTML_RESOURCE);
        Browser browser = new Browser(parent, SWT.EDGE);
        browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
        browser.addProgressListener(new ProgressAdapter()
        {
            @Override
            public void completed(ProgressEvent event)
            {
                new OpenTestWindow(browser);
            }
        });
        browser.setUrl(HTML_RESOURCE);
    }

    private final class OpenTestWindow extends BrowserFunction
    {
        public OpenTestWindow(Browser browser)
        {
            super(browser, "openTestWindow"); //$NON-NLS-1$
        }

        @Override
        public String function(Object[] arguments)
        {
            System.out.println("Function Has Been Called!"); //$NON-NLS-1$
            return null;
        }
    }