2021-01-31

JavaScript Allow List in qutebrowser

web   javascript   index

qutebrowser logo

qutebrowser is a keyboard-focused browser with a minimal GUI. It’s based on Python and PyQt5 and free software, licensed under the GPL. It was inspired by other browsers/addons like dwb and Vimperator/Pentadactyl.

Updated on 2021-02-05

The below solution allows an external manually configured list. However, qutebrowser has a built-in way of achieving something similar with the t commands.

For example tSh would enable JavaScript on the opened site and reload. It will also ask to make the change permanent.

I did not know this before writing this post, thanks to Hund for bringing this to attention.

Link to discussion.


I use qutebrowser sometimes, and it is an excellent fully keyboard driven browser. One thing I miss though, is the control on the loading of scripts. Once you get used to uMatrix, it is difficult to live without.

We can however disable JavaScript altogether, and then selectively allow it for a small number of websites. Not the same level of control, but still could be useful.

c.content.javascript.enabled = False

with config.pattern("https://fosstodon.org/*") as p:
    p.content.javascript.enabled = True

But, instead of adding code for every website, we can have an external plain text list, for example js.sites, and load it in the config.

try:
    with (config.configdir / 'js.sites').open() as js_file:
        js_sites = js_file.read().split("\n")
        js_file.close()

    for js_site in js_sites:
        if js_site != '':
            config.set('content.javascript.enabled', True, js_site)
except FileNotFoundError:
    print('js.sites not found')

Now, we can add the list of websites in js.sites.