Reputation: 7653
Is there a way to use Firebug lite "bookmarklet" feature within eclipse SWT browser?
Upvotes: 4
Views: 3160
Reputation: 64
I tweaked Favonius's solution a bit. In my case we wanted to see inside iframes. I modified the setUrl to load firebug inside the last iframe. In my case it did what we wanted.
browser.setUrl("javascript: function lastIframeDocument(curr){while(curr.getElementsByTagName('iframe')[0]!=null){curr=curr.getElementsByTagName('iframe')[0].contentWindow.document;}return curr;}(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(lastIframeDocument(document),'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');");
Upvotes: 0
Reputation: 718
I can not run on Linux. The exception web page appeared: 'URL cannot be shown'.
Upvotes: 0
Reputation: 13984
Depends on the system browser which your SWT browser is using. For Win7 and IE8, you can have something like this:
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class FirebugLite
{
public static void main(String[] args) {
new FirebugLite().start();
}
public void start()
{
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData.widthHint = SWT.DEFAULT;
gridData.heightHint = SWT.DEFAULT;
shell.setLayoutData(gridData);
shell.setText("Firebug Lite for SWT ;)");
final Browser browser = new Browser(shell, SWT.NONE);
GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
gridData2.widthHint = SWT.DEFAULT;
gridData2.heightHint = SWT.DEFAULT;
browser.setLayoutData(gridData2);
Button button = new Button(shell, SWT.PUSH);
button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
button.setText("Install");
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
browser.setUrl("javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');");
}
});
browser.setUrl("http://stackoverflow.com/questions/12003602/eclipse-swt-browser-and-firebug-lite");
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Note >>
I have used the setUrl()
API. You can try the execute()
but I am not sure whether it would work.
Upvotes: 10