# Buggy code
def _open_editor_cb(self, elem):
    """Open editor after the focus elem was found in open_editor."""
    if elem is None:
        message.error("No element focused!")
        return
    if not elem.is_editable(strict=True):
        message.error("Focused element is not editable!")
        return

    text = elem.value()
    if text is None:
        message.error("Could not get text from the focused element.")
        return
    assert isinstance(text, str), text

    caret_position = elem.caret_position()

    ed = editor.ExternalEditor(self._tabbed_browser)
    ed.editing_finished.connect(functools.partial(self.on_editing_finished, elem))
    ed.edit(text, caret_position)


# Traceback (RuntimeError)
$ python3 -m qutebrowser --temp-basedir --backend webengine --debug tests/end2end/data/hello.txt tests/end2end/data/insert_mode_settings/html/textarea.html
[...]
19:40:01 DEBUG    commands   command:run:524 Calling qutebrowser.browser.commands.CommandDispatcher.open_editor(<qutebrowser.browser.commands.CommandDispatcher>)
19:40:01 DEBUG    webview    webenginetab:_js_cb_single:494 Got element from JS: {'attributes': {'id': 'qute-textarea'}, 'class_name': '', 'id': 1, 'outer_xml': '<textarea id="qute-textarea"></textarea>', 'rects': [{'bottom': 44, 'height': 36, 'left': 8, 'right': 189, 'top': 8, 'width': 181}], 'tag_name': 'TEXTAREA', 'text': '', 'value': ''}
19:40:01 DEBUG    webelem    webelem:is_editable:238 Checking if element is editable: <qutebrowser.browser.webengine.webengineelem.WebEngineElement html='<textarea id="qute-textarea"></textarea>'>
19:40:01 DEBUG    procs      editor:edit:126 Calling "gvim" with args ['-f', '/tmp/qutebrowser-editor-rp75_n9j']
19:40:01 DEBUG    procs      guiprocess:start:139 Starting process.
19:40:01 DEBUG    procs      guiprocess:_pre_start:133 Executing: gvim -f /tmp/qutebrowser-editor-rp75_n9j
19:40:01 DEBUG    procs      guiprocess:on_started:122 Process started.
[...]
19:40:04 DEBUG    commands   command:run:524 Calling qutebrowser.browser.commands.CommandDispatcher.tab_close(<qutebrowser.browser.commands.CommandDispatcher>, False, False, False, False, None)
[...]
19:40:06 DEBUG    procs      guiprocess:on_finished:98 Process finished with code 0, status 0.
19:40:06 DEBUG    procs      editor:on_proc_closed:70 Editor closed
19:40:06 DEBUG    procs      editor:on_proc_closed:87 Read back:
19:40:06 ERROR    misc       crashsignal:exception_hook:205 Uncaught exception
Traceback (most recent call last):
File "/home/florian/proj/qutebrowser/git/qutebrowser/browser/commands.py", line 1617, in on_editing_finished
elem.set_value(text)
File "/home/florian/proj/qutebrowser/git/qutebrowser/browser/webengine/webengineelem.py", line 133, in set_value
self._js_call('set_value', value)
File "/home/florian/proj/qutebrowser/git/qutebrowser/browser/webengine/webengineelem.py", line 103, in _js_call
self._tab.run_js_async(js_code, callback=callback)
File "/home/florian/proj/qutebrowser/git/qutebrowser/browser/webengine/webenginetab.py", line 611, in run_js_async
self._widget.page().runJavaScript(code, world_id)
RuntimeError: wrapped C/C++ object of type WebEngineView has been deleted

# Fixed code
def _open_editor_cb(self, elem):
    """Open editor after the focus elem was found in open_editor."""
    if elem is None:
        message.error("No element focused!")
        return
    if not elem.is_editable(strict=True):
        message.error("Focused element is not editable!")
        return

    text = elem.value()
    if text is None:
        message.error("Could not get text from the focused element.")
        return
    assert isinstance(text, str), text

    caret_position = elem.caret_position()

    ed = editor.ExternalEditor(self._tabbed_browser)
    ed.editing_finished.connect(functools.partial(self.on_editing_finished, elem))
    tab = self._current_widget()
    tab.shutting_down.connect(functools.partial(self.on_editor_orphaned, ed))
    ed.edit(text, caret_position)