Is there a webview for Racket?

162 views
Skip to first unread message

Andre Garzia

unread,
Sep 14, 2019, 5:56:57 PM9/14/19
to Racket Users
Hi Friends,

I was building a little RSS feed reader here when I noticed that I don't know of any webview package to be used from Racket. My search on the package catalog returned nothing.

Is there a webview for Racket? How should I display HTML?

I'd really appreciate any help, even if just pointing me into some application source code that is doing that.

thanks in advance
Andre

--
http://www.andregarzia.com -- All We Do Is Code.
http://fon.nu -- minimalist url shortening service.

Neil Van Dyke

unread,
Sep 14, 2019, 6:39:52 PM9/14/19
to Andre Garzia, Racket Users
Hi, Andre.  For your RSS reader, you're only displaying the RSS items
themselves, not browsing to arbitrary other Web pages within the same
Racket window, right?

For very plain HTML, one thing I would hesitate to use is the *very old*
and *possibly insecure* GUI thing, but it might work for your purpose
(be sure to sanitize any untrusted input HTML):
https://docs.racket-lang.org/browser/index.html

You might be better off using one of the heavier text components of the
Racket GUI library (maybe
"https://docs.racket-lang.org/framework/Editor.html", unless it's
overkill?).  This isn't an HTML/CSS/JS/DOM engine, but I'd think you
could do an RSS item or feed view in it.

Another option, and maybe often the usual way, is to use the user's own
Web browser (or a standalone one you provide), and you only provide the
HTTPS server.

A final option, which could be a ton of work to support cross-platform,
but might be viable if you're targeting a single platform and willing to
support it, is to do FFI with one of the big off-the-shelf Web browser
engines, like WebKit (such as through WebKitGtk).  There's recent work
on Guile bindings for something like that, but Racket has a lot of other
stuff that Guile doesn't yet have.

Separately, for navigating from an RSS reader running as a Racket GUI
program, to view arbitrary Web pages in the user's main Web browser,
see:
https://docs.racket-lang.org/browser/index.html#(mod-path._browser%2Fexternal)

(I'm pleasantly surprised that people are still interested in Web
"syndication", despite some browsers and various commercial forces
moving away from that, for various reasons.  If you're making a
general-purpose RSS reader, an additional protocol to consider also
supporting is "https://en.wikipedia.org/wiki/Atom_(Web_standard)". If
you later want to be even more general-purpose, look at how
"https://en.wikipedia.org/wiki/Gnus" used the power of a Lisp to provide
a sophisticated unified view from various messaging/syndication/etc.
formats, including from Web-scraping.  In addition to threading
features, it also had powerful scoring/ranking interfaces (both crafted
rulesets and ad hoc).  Early research in automated collaborative
filtering (what today we know as things like likes/upvotes, and perhaps
recommendation systems) was also done atop Gnus. I'd say Gnus is
probably still more powerful than any UI we're using today to access the
same or analogous kinds of data sources, and it works on behalf of the
user.  I don't know how much Gnu is developed lately, but it's worth
looking at for ideas of what you can build, even better.)

Andre Garzia

unread,
Sep 17, 2019, 4:59:43 PM9/17/19
to Racket Users
Neil,

Thanks a lot for the detailed response. I am new to Racket, FFI and everything else but I decided to take a shot at it today. I've managed to create a web-view% GUI class that can display web pages on macOS. It is wrapping around WKWebView which is the current way of doing things. I haven't programmed in Objective-C in 16 years, so I a bit over my head here.

I've uploaded it to:

  https://github.com/soapdog/racket-web-view

I don't yet feel that it is ready for the package catalog. I need to fix many things and I'd really welcome help from people who know the current Objective-C way of doing things. WKWebView relies a lot in properties and I can't find a way to deal with them. For example the "delegate" in the code in the repo is not working, nor is the retrieval of the current URL (which in Objective-C should be as simple as "webView.URL")

Anyway, it is a first step towards a real Web View for Racket GUI. It can already load pages and navigate, so it is not completely broken. This is my first FFI project and also my first Racket code after doing Beautiful Racket, it is all brand new to me. Sorry if I'm not idiomatic.

I'd really like feedback, advise and help with this. All programming ecosystems benefit from having Web Views. I hope this becomes my first contribution to Racket.

I also need to do Windows and Linux, but one lion at a time...

Cheers

andre
PS: I tried posting this message a couple times but it was not getting through...

Andre Garzia

unread,
Sep 20, 2019, 8:42:57 AM9/20/19
to Neil Van Dyke, Racket Users
Neil,

Thanks a lot for the detailed response. I am new to Racket, FFI and
everything else but I decided to take a shot at it today. I've managed
to create a web-view% GUI class that can display web pages on macOS. It
is wrapping around WKWebView which is the current way of doing things. I
haven't programmed in Objective-C in 16 years, so I a bit over my head here.

I've uploaded it to:

  https://github.com/soapdog/racket-web-view

I don't yet feel that it is ready for the package catalog. I need to fix
many things and I'd really welcome help from people who know the current
Objective-C way of doing things. WKWebView relies a lot in properties
and I can't find a way to deal with them. For example the "delegate" in
the code in the repo is not working, nor is the retrieval of the current
URL (which in Objective-C should be as simple as "webView.URL")

Anyway, it is a first step towards a real Web View for Racket GUI. It
can already load pages and navigate, so it is not completely broken.
This is my first FFI project and also my first Racket code after doing
Beautiful Racket, it is all brand new to me. Sorry if I'm not idiomatic.

I'd really like feedback, advise and help with this. All programming
ecosystems benefit from having Web Views. I hope this becomes my first
contribution to Racket.

I also need to do Windows and Linux, but one lion at a time...

Cheers

andre

Reply all
Reply to author
Forward
0 new messages