Web browser RPC question

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Kurt Granroth
Date:  
Subject: Web browser RPC question
On Jan 14, 2004, at 2:21 PM, Vaughn Treude wrote:
> Here's a question for you web gurus: what I want to do is to control
> a web
> browser programmatically, specifically to tell an open browser window
> to open
> a new URL automagically rather than typing it in. It could be any
> Linux
> browser: Mozilla, Netscape, Galeon, Konqueror, Opera - maybe even
> Lynx.


Konqueror is HUGELY scriptable.. as are quite a few KDE apps. They use
the DCOP communication protocol which allows lightweight (but very easy
to use) RPC. You can query and modify almost every property it has.
This includes such things as (but not limited to):

o Current URL browsing
o All menu items
o Most 'widgets' associated with the window ("forms" and the like)
o Bookmarks
o History
o Nearly anything else that Konqueror can do

This is accessible via shell scripts using the 'dcop' command or
through Python (with PyKDE, I think) or C or C++. If you want to
browse through which DCOP functions Konqueror (or any other KDE app)
supports, just fire up the 'kdcop' command. It is a graphical browser
of all supported functions.

There is a good into article on DCOP scripting in general here:
http://www.linux-magazine.com/issue/36/KDE_Scripting_DCOP.pdf

A few random Konqueror DCOP commands:

# open a new browser at google.com
% dcop konqueror-1187 default createBrowserWindow http://www.google.com

# find out the current browsing history
% dcop konqueror-1187 KonqHistoryManager allURLs

# create a new tabbed window, open up google.com in it, activate the
original tab, open up kde.org in it
% dcop konqueror-1187 konqueror-mainwindow\#1/action/newtab activate
% dcop konqueror-1187 konqueror-mainwindow\#1 openURL
http://www.google.com
% dcop konqueror-1187 konqueror-mainwindow\#1/action/activateprevtab
activate
% dcop konqueror-1187 konqueror-mainwindow\#1 openURL http://www.kde.org

# select all the text on a specific open page, copy it to the
clipboard, paste it to a 'kate' editor window
% dcop konqueror-1187 html-widget6 selectAll
% dcop konqueror-1187 konqueror-mainwindow\#1/action/copy activate
% dcop kate ClipboardInterface\#1-1 paste

Hopefully you get the picture. Almost any operation that can be done
via menus (or behind the scenes) can be scripted using DCOP. And this
holds true for more than just Konqueror... check kdcop on KMail and
Konsole just for fun :-)

Have fun!
Kurt