Skip to content

Instantly share code, notes, and snippets.

@jakeogh
Created February 4, 2016 03:14
Show Gist options
  • Save jakeogh/361497ce947067bf2430 to your computer and use it in GitHub Desktop.
Save jakeogh/361497ce947067bf2430 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# https://davidsimpson.me/labs/--allow-running-insecure-content/
# http://trac.webkit.org/browser/trunk/Source/WebCore/page/ContentSecurityPolicy.h
# WebKit2GTK+ Reference Manual: http://webkitgtk.org/reference/webkit2gtk/stable/
# http://webkitgtk.org/reference/webkit2gtk/stable/index-all.html
from gi.repository import Gtk # http://pygtk.org/pygtk2reference/class-gtkwidget.html
from gi.repository import WebKit2
global custom_settings
custom_settings = True
#custom_settings = False
import sys
#import IPython; IPython.embed()
class BrowserView:
def __init__(self, url):
window = Gtk.Window() # https://developer.gnome.org/gtk3/stable/GtkWindow.html
window.connect('delete-event', Gtk.main_quit) # http://www.pygtk.org/docs/pygobject/class-gobject.html#method-gobject--connect
# https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-delete-event
self.view = WebKit2.WebView() # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html https://lazka.github.io/pgi-docs/WebKit2-3.0/classes/WebView.html
self.settings = self.view.get_settings()
if custom_settings:
self.settings.set_allow_modal_dialogs(False) # https://bugzilla.mozilla.org/show_bug.cgi?id=194404
self.settings.set_auto_load_images(True)
print("settings.get_default_charset():", self.settings.get_default_charset())
# self.settings.set_accelerated_2d_canvas(False) # https://bugs.launchpad.net/oxide/+bug/1352631
self.settings.set_enable_caret_browsing(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-caret-browsing
# self.settings.set_developer_extras(True) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-developer-extras
self.settings.set_enable_dns_prefetching(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-dns-prefetching
self.settings.set_enable_frame_flattening(True) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-frame-flattening
self.settings.set_enable_fullscreen(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-fullscreen
self.settings.set_enable_html5_database(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-html5-database
self.settings.set_enable_html5_local_storage(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-html5-local-storage
self.settings.set_enable_hyperlink_auditing(False) # uug.
self.settings.set_enable_java(False)
self.settings.set_enable_javascript(True)
self.settings.set_enable_media_stream(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-media-stream
self.settings.set_enable_mediasource(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-mediasource
self.settings.set_enable_offline_web_application_cache(False)
self.settings.set_enable_page_cache(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-page-cache
self.settings.set_enable_plugins(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-plugins
self.settings.set_enable_private_browsing(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-private-browsing #breals TLS?
# self.settings.set_enable_running_of_insecure_content(False) # http://www.webkitgtk.org/reference/webkit2gtk/stable/WebKitSecurityManager.html
# self.settings.set_enable_scripts(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-scripts
self.settings.set_enable_resizable_text_areas(True) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-resizable-text-areas
self.settings.set_enable_site_specific_quirks(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-site-specific-quirks
self.settings.set_enable_smooth_scrolling(True) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-smooth-scrolling
self.settings.set_enable_spatial_navigation(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-spatial-navigation
self.settings.set_enable_tabs_to_links(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#WebKitSettings--enable-tabs-to-links
self.settings.set_enable_webaudio(False) # http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#WebKitSettings--enable-webaudio
self.settings.set_enable_webgl(True)
self.settings.set_enable_write_console_messages_to_stdout(True)
self.view.load_uri(url)
window.add(self.view)
window.fullscreen()
window.show_all()
if __name__ == "__main__":
# print(dir(WebKit2))
print(sys.argv)
print(len(sys.argv))
if len(sys.argv) == 1:
# url = 'https://davidsimpson.me/labs/--allow-running-insecure-content/'
url = 'https://people.mozilla.org/~mkelly/mixed_test.html'
#url = 'https://www.khronos.org/registry/webgl/sdk/tests/webgl-conformance-tests.html'
else:
url = sys.argv[1]
BrowserView(url)
Gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment