Build your own browser

Build your own browser using GTK and webkit2.

./browser "http://www.google.com"


To add content blocking, connect to the "decide-policy" signal and use webkit_policy_decision_ignore().


browser.c

#include <gtk/gtkx.h>
#include <webkit2/webkit2.h>

int main(int argc, char* argv[])
{
  // Initialize GTK+
  gtk_init(&argc, &argv);

  // Create an 800x600 window that will contain the browser instance
  GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  g_signal_connect(window, "delete-event", gtk_main_quit, NULL);

  gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
    
  // Create a browser instance
  WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());

  gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(webView));

  // Load a web page into the browser instance
  webkit_web_view_load_uri(webView, argv[1]);

  // Make sure the main window and all its contents are visible
  gtk_widget_show_all(window);

  // Run the main GTK+ event loop
  gtk_main();

  return 0;
}

 
 
Compile the file using following command to generate executable browser.
 
gcc browser.c $(pkg-config --libs --cflags gtk+-3.0 webkit2gtk-4.0) -o browser

Comments

Popular posts from this blog

GNU Emacs as a Comic Book Reader

Data Visualization with GNU Emacs

Mozilla Readability in GNU Emacs