Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Problem when handling form submission with WebKitGTK+ 2.14
# To run: install (Ubuntu package names)
# ``python3-gi``, ``gir1.2-gtk-3.0``, ``gir1.2-webkit2-4.0``,
# then do ``python3``
import ctypes
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gtk, WebKit2
def main():
window = Gtk.Window()
window.connect('delete-event', lambda *_: Gtk.main_quit())
view = WebKit2.WebView()
view.connect('submit-form', on_submit_form, [])
view.load_html('<form> <input name=foo> <input type=submit> </form>')
def on_submit_form(view, request, refs):
# Handle the form submission (= do something with the submitted data).
for k, v in request.get_text_fields().items():
# Note how I have to do the extra `ctypes.string_at` step,
# because `k` and `v` are pointers (Python integers, not bytestrings).
# I think this may be a bug, but it's unrelated to my problem.
print(ctypes.string_at(k) + b'=' + ctypes.string_at(v))
# After handling the form, we want to prevent its further submission.
# This works with WebKitGTK+ 2.12, but under 2.14 the WebView just "hangs".
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.