1

I am having problems with an Eclipse SWT Browser not loading certain styles on one machine. I am expecting the machine to use IE 10 as the native browser but I am not sure how I can confirm this. Is there a way to determine the type/version of the Browser which SWT decides to load the page using?

Baz
  • 36,440
  • 11
  • 68
  • 94
Aaron B
  • 13
  • 4

1 Answers1

0

Based on the accepted answer to this question:

How can you detect the version of a browser?

you can do something like this:

public static void main(String[] args)
{
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Stackoverflow");
    shell.setLayout(new FillLayout());

    Browser browser = new Browser(shell, SWT.NONE);

    browser.addProgressListener(new ProgressListener()
    {
        @Override
        public void changed(ProgressEvent progressEvent)
        {
        }

        @Override
        public void completed(ProgressEvent progressEvent)
        {
            System.out.println(browser.evaluate("var ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\\/))\\/?\\s*(\\d+)/i) || []; if (/trident/i.test(M[1])) { tem = /\\brv[ :]+(\\d+)/g.exec(ua) || []; return 'IE ' + (tem[1] || ''); } if (M[1] === 'Chrome') { tem = ua.match(/\\b(OPR|Edge)\\/(\\d+)/); if (tem != null) return tem.slice(1).join(' ').replace('OPR', 'Opera'); } M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?']; if ((tem = ua.match(/version\\/(\\d+)/i)) != null) M.splice(1, 1, tem[1]); return M.join(' ');"));
        }
    });
    browser.setUrl("https://www.google.co.uk");

    shell.pack();
    shell.open();

    while (!shell.isDisposed())
    {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

It outputs IE 11 in my case.

Community
  • 1
  • 1
Baz
  • 36,440
  • 11
  • 68
  • 94
  • Thanks! This is just what I was looking for. Now I found out that the machines are all loading the same browser version through SWT, IE 7. So now I am confused as to why the SWT running the same browser on one machine would display certain styles incorrectly but everything displays fine on the other machine. Weird. I have also tried resetting the internet explorer settings for that machine but nothing changed. – Aaron B Aug 10 '16 at 19:03