Community
Participate
Working Groups
Playing with org.eclipse.ui.examples.rcp.browser while trying to develop some code for accessing browser cookies using DOM, I've realized that if (browser.execute("window.status=document.cookie;")) { String value = (String) browser.getData("query"); } doesn't return any data, regardless if the site contains cookies or not. Adding alert statement verifies that cookies indeed do exist. Since the code also had a StatusTextListener attached, I've realized though that the updates to window.status end up in the status listener instead which correctly shows the cookies. This behaviour could be reproduced with both Mozilla 3.0 and IE 7.0 browsers. Not sure if I'm doing something entirely stupid here or this is an issue of the browser widget?
Created attachment 105734 [details] mylyn/context/zip browser example mylyn context
I think the snippet below is what you want (derived from http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet160.java ). If I'm wrong then please follow up. public static void main(String [] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Browser browser = new Browser(shell, SWT.NONE); browser.addStatusTextListener(new StatusTextListener() { public void changed(StatusTextEvent event) { browser.setData("query", event.text); } }); browser.addProgressListener(new ProgressAdapter() { public void completed(ProgressEvent event) { browser.execute("window.status=document.cookie;"); String value = (String)browser.getData("query"); System.out.println("document.cookie: " + value); } }); browser.setUrl("google.com"); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
True- I had totally overlooked the connection between the status listener and the getData...