# Buggy code
def code(self):
    """Return the processed JavaScript code of this script.

    Adorns the source code with GM_* methods for Greasemonkey
    compatibility and wraps it in an IIFE to hide it within a
    lexical scope. Note that this means line numbers in your
    browser's debugger/inspector will not match up to the line
    numbers in the source script directly.
    """
    template = jinja.js_environment.get_template("greasemonkey_wrapper.js")
    return template.render(
        scriptName="/".join([self.namespace or "", self.name]),
        scriptInfo=self._meta_json(),
        scriptMeta=self.script_meta,
        scriptSource=self._code,
    )


# Traceback (jinja2.exceptions.TemplateAssertionError)
Traceback (most recent call last):
File "/home/jay/.local/lib/python3.5/site-packages/qutebrowser/browser/webengine/webview.py", line 355, in _inject_userjs
_add_script(script, QWebEngineScript.DocumentReady)
File "/home/jay/.local/lib/python3.5/site-packages/qutebrowser/browser/webengine/webview.py", line 343, in _add_script
new_script.setSourceCode(script.code())
File "/home/jay/.local/lib/python3.5/site-packages/qutebrowser/browser/greasemonkey.py", line 107, in code
template = jinja.js_environment.get_template('greasemonkey_wrapper.js')
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 812, in get_template
return self._load_template(name, self.make_globals(globals))
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 786, in _load_template
template = self.loader.load(self, name, globals)
File "/usr/lib/python3/dist-packages/jinja2/loaders.py", line 125, in load
code = environment.compile(source, name, filename)
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 565, in compile
self.handle_exception(exc_info, source_hint=source_hint)
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 754, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3/dist-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "javascript/greasemonkey_wrapper.js", line 2, in template
File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 515, in _generate
return generate(source, self, name, filename, defer_init=defer_init)
File "/usr/lib/python3/dist-packages/jinja2/compiler.py", line 62, in generate
generator.visit(node)
File "/usr/lib/python3/dist-packages/jinja2/visitor.py", line 38, in visit
return f(node, *args, **kwargs)
File "/usr/lib/python3/dist-packages/jinja2/compiler.py", line 816, in visit_Template
self.blockvisit(node.body, frame)
File "/usr/lib/python3/dist-packages/jinja2/compiler.py", line 492, in blockvisit
self.visit(node, frame)
File "/usr/lib/python3/dist-packages/jinja2/visitor.py", line 38, in visit
return f(node, *args, **kwargs)
File "/usr/lib/python3/dist-packages/jinja2/compiler.py", line 1353, in visit_Output
self.visit(argument, frame)
File "/usr/lib/python3/dist-packages/jinja2/visitor.py", line 38, in visit
return f(node, *args, **kwargs)
File "/usr/lib/python3/dist-packages/jinja2/compiler.py", line 1565, in visit_Filter
self.fail('no filter named %r' % node.name, node.lineno)
File "/usr/lib/python3/dist-packages/jinja2/compiler.py", line 427, in fail
raise TemplateAssertionError(msg, lineno, self.name, self.filename)
jinja2.exceptions.TemplateAssertionError: no filter named 'tojson'

# Fixed code
def code(self):
    """Return the processed JavaScript code of this script.

    Adorns the source code with GM_* methods for Greasemonkey
    compatibility and wraps it in an IIFE to hide it within a
    lexical scope. Note that this means line numbers in your
    browser's debugger/inspector will not match up to the line
    numbers in the source script directly.
    """
    template = jinja.js_environment.get_template("greasemonkey_wrapper.js")
    return template.render(
        scriptName=javascript.string_escape(
            "/".join([self.namespace or "", self.name])
        ),
        scriptInfo=self._meta_json(),
        scriptMeta=javascript.string_escape(self.script_meta),
        scriptSource=self._code,
    )