<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://dev1galaxy.org/extern.php?action=feed&amp;tid=7377&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / A simple browser in 100 lines of code.]]></title>
		<link>https://dev1galaxy.org/viewtopic.php?id=7377</link>
		<description><![CDATA[The most recent posts in A simple browser in 100 lines of code..]]></description>
		<lastBuildDate>Mon, 25 Aug 2025 00:15:29 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[A simple browser in 100 lines of code.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=57573#p57573</link>
			<description><![CDATA[<p>This is not intended to be a serious candidate for a browser, this is just a simple exercise in using a tiny amount of code (and some not-so-tiny libraries) to create a working browser. In the same spirit as many others who have done similar in the last 16 years that i&#039;ve been using Linux, there&#039;s lots of examples from back in the day, this is a modern one using current daedalus packages. A determined user could start with this skeleton and do lots of things. <img src="https://dev1galaxy.org/img/smilies/wink.png" width="15" height="15" alt="wink" /></p><p>The buttons work, url bar works (it is NOT a search bar, you will need to add a working url thusly &quot;dev1galaxy.org&quot;, it will add the https etc.).</p><p>Not safe for sketchy sites obviously, but a fun toy just to see what works. All in 100 lines of code (around ~75 if you take out comments and spaces).</p><p>Depends are listed in the code, obviously there&#039;s other things you need like gtk and python3, but any vanilla Devuan should have &#039;em.</p><div class="codebox"><pre class="vscroll"><code>#!/usr/bin/env python3

# Mini-browser experimental. Don&#039;t use on unsecure sites!
# Dependencies:
# libjavascriptcoregtk-4.1-0
# libwebkit2gtk-4.1-0
# gir1.2-javascriptcoregtk-4.1 (2.48.0-1~deb12u1)
# gir1.2-soup-3.0 (3.2.2-2)
# gir1.2-webkit2-4.1 (2.48.0-1~deb12u1)

import gi
gi.require_version(&quot;Gtk&quot;, &quot;3.0&quot;)
gi.require_version(&quot;WebKit2&quot;, &quot;4.1&quot;)
from gi.repository import Gtk, WebKit2

class MiniBrowser:
    def __init__(self, homepage):
        # Store homepage
        self.homepage = homepage

        # Set up main window
        self.window = Gtk.Window()
        self.window.set_title(&quot;Dev1 Browser&quot;)
        self.window.set_icon_name(&quot;web-browser&quot;)
        self.window.set_default_size(800, 600)
        self.window.connect(&quot;destroy&quot;, Gtk.main_quit)

        # Create a WebView
        self.webview = WebKit2.WebView()
        self.webview.load_uri(self.homepage)

        # Handle link clicks
        self.webview.connect(&quot;decide-policy&quot;, self.on_policy)

        # Create URL entry
        self.url_entry = Gtk.Entry()
        self.url_entry.set_placeholder_text(&quot;Enter URL (e.g., https://dev1galaxy.org)&quot;)
        self.url_entry.set_text(self.homepage)
        self.url_entry.connect(&quot;activate&quot;, self.on_url_entry_activate)
        self.webview.connect(&quot;load-changed&quot;, self.on_load_changed)

        # Create navigation buttons
        self.back_button = Gtk.Button(label=&quot;Back&quot;)
        self.forward_button = Gtk.Button(label=&quot;Forward&quot;)
        self.home_button = Gtk.Button(label=&quot;Home&quot;)

        # Connect buttons to functions
        self.back_button.connect(&quot;clicked&quot;, self.go_back)
        self.forward_button.connect(&quot;clicked&quot;, self.go_forward)
        self.home_button.connect(&quot;clicked&quot;, self.go_home)

        # Create a horizontal box for the nav bar and URL entry
        nav_bar = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=5)
        nav_bar.set_margin_start(10)  # 10px left margin
        nav_bar.set_margin_top(5) # 5px top margin
        nav_bar.pack_start(self.back_button, False, False, 0)
        nav_bar.pack_start(self.forward_button, False, False, 0)
        nav_bar.pack_start(self.home_button, False, False, 0)
        nav_bar.pack_start(self.url_entry, True, True, 5)  # URL entry expands to fill space

        # Create a vertical box for nav bar and webview
        main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5)
        main_box.pack_start(nav_bar, False, False, 0)
        main_box.pack_start(self.webview, True, True, 0)

        # Add main box to window and show
        self.window.add(main_box)
        self.window.show_all()

    def on_policy(self, webview, decision, decision_type):
        # Allow navigation (link clicks)
        return False  # False means &quot;proceed&quot;, weird right?

    def on_url_entry_activate(self, entry):
        url = entry.get_text().strip()
        if not url.startswith((&#039;http://&#039;, &#039;https://&#039;)):
            url = &#039;https://&#039; + url
        self.webview.load_uri(url)

    def on_load_changed(self, webview, load_event):
        if load_event == WebKit2.LoadEvent.COMMITTED:
            current_url = self.webview.get_uri()
            self.url_entry.set_text(current_url)

    def go_back(self, button):
        if self.webview.can_go_back():
            self.webview.go_back()

    def go_forward(self, button):
        if self.webview.can_go_forward():
            self.webview.go_forward()

    def go_home(self, button):
        self.webview.load_uri(self.homepage)
        self.url_entry.set_text(self.homepage)

if __name__ == &quot;__main__&quot;:
    homepage = &quot;https://dev1galaxy.org/&quot;
    browser = MiniBrowser(homepage)
    Gtk.main()</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (greenjeans)]]></author>
			<pubDate>Mon, 25 Aug 2025 00:15:29 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=57573#p57573</guid>
		</item>
	</channel>
</rss>
