# Buggy code
def _inject_userjs(self, frame):
    """Inject user JavaScripts into the page.

    Args:
        frame: The QWebFrame to inject the user scripts into.
    """
    url = frame.url()
    if url.isEmpty():
        url = frame.requestedUrl()

    log.greasemonkey.debug(
        "_inject_userjs called for {} ({})".format(frame, url.toDisplayString())
    )

    greasemonkey = objreg.get("greasemonkey")
    scripts = greasemonkey.scripts_for(url)
    # QtWebKit has trouble providing us with signals representing
    # page load progress at reasonable times, so we just load all
    # scripts on the same event.
    toload = scripts.start + scripts.end + scripts.idle

    if url.isEmpty():
        # This happens during normal usage like with view source but may
        # also indicate a bug.
        log.greasemonkey.debug(
            "Not running scripts for frame with no url: {}".format(frame)
        )
        assert not toload, toload

    for script in toload:
        if frame is self.mainFrame() or script.runs_on_sub_frames:
            log.webview.debug("Running GM script: {}".format(script.name))
            frame.evaluateJavaScript(script.code())


# Traceback (RuntimeError)
13:18:20 DEBUG    greasemonkey webpage:_inject_userjs:312 _inject_userjs called for <PyQt5.QtWebKitWidgets.QWebFrame object at 0x7fadc1f15288> (https://information.rapid7.com/index.php/form/XDFrame)
13:18:20 DEBUG    greasemonkey webpage:_inject_userjs:312 _inject_userjs called for <PyQt5.QtWebKitWidgets.QWebFrame object at 0x7fae080e8ca8> (https://www.google.com/recaptcha/api2/anchor?k=6LfW8QoUAAAAAN7jy-NRqt6xhlA_5LdQIyWI73V-&amp;co=aHR0cHM6Ly93d3cucmFwaWQ3LmNvbTo0NDM.&amp;hl=en&amp;v=v1517812337239&amp;theme=light&amp;size=normal&amp;cb=axrjnt33j5tk)
13:18:20 DEBUG    greasemonkey webpage:_connect_userjs_signals:101 Connecting to frame <PyQt5.QtWebKitWidgets.QWebFrame object at 0x7fadc1f151f8> ()
13:18:20 DEBUG    webview    webpage:acceptNavigationRequest:497 navigation request: url about:blank, type NavigationTypeOther, target ClickTarget.normal override None
13:18:20 DEBUG    greasemonkey webpage:_inject_userjs:312 _inject_userjs called for <PyQt5.QtWebKitWidgets.QWebFrame object at 0x7fadc1f151f8> (about:blank)
13:18:20 ERROR    misc       crashsignal:exception_hook:216 Uncaught exception
Traceback (most recent call last):
File "/home/foka1/Downloads/qutebrowser-1.1.1/qutebrowser/browser/webkit/webpage.py", line 307, in _inject_userjs
url = frame.url()
RuntimeError: wrapped C/C++ object of type QWebFrame has been deleted

# Fixed code
def _inject_userjs(self, frame):
    """Inject user JavaScripts into the page.

    Args:
        frame: The QWebFrame to inject the user scripts into.
    """
    if sip.isdeleted(frame):
        log.greasemonkey.debug("_inject_userjs called for deleted frame!")
        return

    url = frame.url()
    if url.isEmpty():
        url = frame.requestedUrl()

    log.greasemonkey.debug(
        "_inject_userjs called for {} ({})".format(frame, url.toDisplayString())
    )

    greasemonkey = objreg.get("greasemonkey")
    scripts = greasemonkey.scripts_for(url)
    # QtWebKit has trouble providing us with signals representing
    # page load progress at reasonable times, so we just load all
    # scripts on the same event.
    toload = scripts.start + scripts.end + scripts.idle

    if url.isEmpty():
        # This happens during normal usage like with view source but may
        # also indicate a bug.
        log.greasemonkey.debug(
            "Not running scripts for frame with no url: {}".format(frame)
        )
        assert not toload, toload

    for script in toload:
        if frame is self.mainFrame() or script.runs_on_sub_frames:
            log.webview.debug("Running GM script: {}".format(script.name))
            frame.evaluateJavaScript(script.code())