Vieb
Vieb copied to clipboard
Feature Request: Javascript enable/disable
Hello. Something to turn js on/off
nmap toggle-javascript on/off
or set permissionjavascript= on/off
Thanks!
nmap
is for normal mode keyboard mappings, so that won't be it, but we could make a setting for it if it's an option to disable JavaScript in Electron.
I briefly looked into implementing this because there are Electron options for this, and it does work with a couple of quirks. However, I won't be implementing this myself for now for these reasons:
- You can only change the settings for new tabs (or ones that you close and reopen). Which is kind of inconvenient, but not a big problem.
- Special pages such as newtab, help or version don't work. This is a big issue, as you won't be able to find help on the setting that you changed to disable JavaScript in the first place...
For now this does mean that I won't be able to implement this until a different solution is found to disable JavaScript. For those interested in continuing the work (by making the special pages work), the patch/diff for a working proof of concept is listed below:
diff --git a/app/renderer/settings.js b/app/renderer/settings.js
index c53688e..fd236ba 100644
--- a/app/renderer/settings.js
+++ b/app/renderer/settings.js
@@ -150,6 +150,7 @@ const defaultSettings = {
"timeout": true,
"timeoutlen": 1000,
"vimcommand": "gvim",
+ "webfeatures": "javascript,images,webgl",
"windowtitle": "simple"
}
let allSettings = {}
@@ -166,7 +167,8 @@ const listLike = [
"spelllang",
"startuppages",
"storenewvisits",
- "suggestorder"
+ "suggestorder",
+ "webfeatures"
]
const validOptions = {
"adblocker": ["off", "static", "update", "custom"],
@@ -558,6 +560,15 @@ const checkOther = (setting, value) => {
if (setting === "suggestorder") {
return checkSuggestOrder(value)
}
+ if (setting === "webfeatures") {
+ for (const val of value.split(",").filter(f => f)) {
+ if (!["javascript", "images", "webgl"].includes(val)) {
+ notify(`Invalid webfeature passed: ${val}, `
+ + "must be one of: javascript, images or webgl", "warn")
+ return false
+ }
+ }
+ }
return true
}
diff --git a/app/renderer/tabs.js b/app/renderer/tabs.js
index 74b1640..b8b956b 100644
--- a/app/renderer/tabs.js
+++ b/app/renderer/tabs.js
@@ -398,12 +398,16 @@ const unsuspendPage = page => {
webview.setAttribute(attr, page.getAttribute(attr))
}
})
+ let webpreferences = "spellcheck=yes"
if (appConfig().autoplay === "user") {
- webview.setAttribute("webpreferences",
- "spellcheck=yes,autoplayPolicy=document-user-activation-required")
- } else {
- webview.setAttribute("webpreferences", "spellcheck=yes")
+ webpreferences += ",autoplayPolicy=document-user-activation-required"
+ }
+ for (const feature of ["javascript", "images", "webgl"]) {
+ if (!getSetting("webfeatures").includes(feature)) {
+ webpreferences += `,${feature}=false`
+ }
}
+ webview.setAttribute("webpreferences", webpreferences)
const sessionName = page.getAttribute("container")
ipcRenderer.send("create-session", `persist:${sessionName}`,
getSetting("adblocker"), getSetting("cache") !== "none")
@Jelmerro Unfortunately I do not code :/ All I know is that the projects Min-Browser and Elza-Browser are Electron based and does have a Disable JS
option. The answer is probably in their code. Thanks for your efforts. Very appreciated.
Having looked at this again, this feature would also break follow mode and any other code that needs to run inside the page to get information from it, so I don't see this happening anytime soon using Electron's webpreferences, though there might be a way to do this by intercepting JS resources and blocking those.
I figured out a way to block it on request level, so this will be making it's way into Vieb soon along with the option to block all kinds of other resources such as stylesheets, images, media etc. etc.
Released in 9.4.0 as general resource blocking, see :help resourcetypes
for details! :tada: