unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Noé Lopez" <noelopez@free.fr>
To: 68604@debbugs.gnu.org
Subject: bug#68604: [PATCH] Add user option to disable JavaScript in xwidget webview
Date: Sat, 20 Jan 2024 00:16:33 +0100	[thread overview]
Message-ID: <d619f41d-7a54-4158-9d7f-fbb16a7c3fbb@free.fr> (raw)

[-- Attachment #1: Type: text/plain, Size: 865 bytes --]

Hi,

This patch adds a new variable for xwidget webkit that allows users to
disable javascript.  Javascript is often used by websites for tracking,
advertisements, cookies and being obnoxious in general.

As I mostly use xwidget for viewing online documentation and simple
pages, disabling javascript is a very elegant solution to get rid of
everything obnoxious and browse with ease.  I hope this patch can be
useful for people with the same use case as me where javascript is not
needed.


In GNU Emacs 30.0.50 (build 5, x86_64-pc-linux-gnu, GTK+ Version
  3.24.38, cairo version 1.18.0) of 2024-01-19 built on navi
Repository revision: bd5bfc29137b6e452e1900a1fc3cf09e77959133
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101010
System Description: Void Linux

Configured using:
  'configure --with-xwidgets'

[-- Attachment #2: 0001-Add-user-option-to-disable-JavaScript-in-xwidget-web.patch --]
[-- Type: text/x-patch, Size: 3574 bytes --]

From cea55d4953cb70a8a4c3ba9c21aad68efc7475f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?No=C3=A9=20Lopez?= <noelopez@free.fr>
Date: Fri, 19 Jan 2024 23:40:53 +0100
Subject: [PATCH] Add user option to disable JavaScript in xwidget webview

* etc/NEWS:
* doc/emacs/misc.texi (Embedded Webkit Widgets):
Document the change.
* lisp/xwidget.el:
* src/xwidget.el:
Add the 'xwidget-webkit-disable-javascript' variable to disable
JavaScript in WebKit sessions.
---
 doc/emacs/misc.texi | 8 ++++++++
 etc/NEWS            | 7 +++++++
 lisp/xwidget.el     | 7 +++++++
 src/xwidget.c       | 7 +++++++
 4 files changed, 29 insertions(+)

diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index 7eb28f56826..d39d98678a0 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -3009,6 +3009,14 @@ Embedded WebKit Widgets
 
 It is bound to @kbd{H}.
 
+@vindex xwidget-webkit-disable-javascript
+@cindex disabling javascript in webkit buffers
+  JavaScript is enabled by default inside WebKit buffers, this can be
+undesirable as websites often use it to track your online activity. It
+can be disabled by setting the variable @code{xwidget-webkit-disable-javascript} to @code{t}.
+You must kill all WebKit buffers for this setting to take effect after
+it is changed.
+
 @node Browse-URL
 @subsection  Following URLs
 @cindex World Wide Web
diff --git a/etc/NEWS b/etc/NEWS
index 735a05f6579..33655663bd8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1254,6 +1254,13 @@ chat buffers use by default.
 *** New command 'customize-dirlocals'.
 This command pops up a buffer to edit the settings in ".dir-locals.el".
 
+** Xwidget Webkit
+
++++
+*** New user option 'xwidget-webkit-disable-javascript'
+This allows disabling JavaScript in xwidget webkit
+sessions.
+
 \f
 * New Modes and Packages in Emacs 30.1
 
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index cca01c8cb3a..2fb79bb7b1d 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -116,6 +116,13 @@ xwidget-webkit-cookie-file
   :type '(choice (const :tag "Do not store cookies" nil) file)
   :version "29.1")
 
+(defcustom xwidget-webkit-disable-javascript nil
+  "If non-nil, disables the execution of JavaScript in xwidget webkit sessions.
+You must kill all xwidget-webkit buffers for this setting to take
+effect after changing it."
+  :type '(boolean)
+  :version "30.0")
+
 ;;;###autoload
 (defun xwidget-webkit-browse-url (url &optional new-session)
   "Ask xwidget-webkit to browse URL.
diff --git a/src/xwidget.c b/src/xwidget.c
index 58910459142..fc0055963c6 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -379,6 +379,7 @@ DEFUN ("make-xwidget",
 	  /* Enable the developer extras.  */
 	  settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (xw->widget_osr));
 	  g_object_set (G_OBJECT (settings), "enable-developer-extras", TRUE, NULL);
+	  g_object_set (G_OBJECT (settings), "enable-javascript", !Vxwidget_webkit_disable_javascript, NULL);
 	}
 
       gtk_widget_set_size_request (GTK_WIDGET (xw->widget_osr), xw->width,
@@ -3972,6 +3973,12 @@ syms_of_xwidget (void)
 	       doc: /* List of all xwidget views.  */);
   Vxwidget_view_list = Qnil;
 
+  DEFVAR_BOOL("xwidget-webkit-disable-javascript", Vxwidget_webkit_disable_javascript,
+	      doc: /* If non-nil, disables the execution of JavaScript in xwidget webkit sessions.
+You must kill all xwidget-webkit buffers for this setting to take
+effect after changing it.  */);
+  Vxwidget_webkit_disable_javascript = Qnil;
+
   Fprovide (intern ("xwidget-internal"), Qnil);
 
   id_to_xwidget_map = CALLN (Fmake_hash_table, QCtest, Qeq,
-- 
2.43.0


             reply	other threads:[~2024-01-19 23:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 23:16 Noé Lopez [this message]
2024-01-20  7:57 ` bug#68604: [PATCH] Add user option to disable JavaScript in xwidget webview Eli Zaretskii
2024-01-20 12:52   ` Noé Lopez
2024-01-20 13:03     ` Eli Zaretskii
2024-03-01 21:51       ` Noé Lopez
2024-03-02  7:25         ` Eli Zaretskii
2024-03-03  5:05         ` Richard Stallman
2024-03-03 17:10           ` Noé Lopez
2024-03-04  2:01             ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-06  2:22               ` Richard Stallman
2024-03-06  4:00                 ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-09  8:44                   ` Eli Zaretskii
2024-03-09 10:23                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-14  9:34                       ` Eli Zaretskii
2024-03-09 13:58                     ` Noé Lopez
2024-03-10  3:00                   ` Richard Stallman
2024-03-10  3:12                     ` Po Lu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-13  2:27                       ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d619f41d-7a54-4158-9d7f-fbb16a7c3fbb@free.fr \
    --to=noelopez@free.fr \
    --cc=68604@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).