Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

userscript loading on every tab? #1041

Open
jindamvani opened this issue May 16, 2023 · 5 comments
Open

userscript loading on every tab? #1041

jindamvani opened this issue May 16, 2023 · 5 comments

Comments

@jindamvani
Copy link

Current Behavior:
userscript loading on every tab

Desired Behavior:
should not load on every tab

How can we reproduce it (step by step):

Environment:

Linux Distribution & Version: debian bookworm
Output of luakit --version:
luakit 2.3.3
built with webkit 2.38.2 (installed version: 2.40.1)

Screenshot_2023-05-16_16-28-00

Note about webkit issues:

If you're reporting a rendering issue, please test it with the gnome
browser ephiphany as well. If the issue occurs there too, we're very
likely not able to help. These issues should be reported to webkit:
https://bugs.webkit.org

@taobert
Copy link
Contributor

taobert commented May 17, 2023

I haven't really looked into this enough to be confident that i understand what's going on here,
so please take the following with a grain of salt.

Currently, luakit does indeed (de)activate a given userscript globally.
(A pull request to change that to per-tab might be considered, but i'm personally not convinced it'd be valuable.)
However, userscripts can be restricted to certain domains by changing the userscript header.
The file you link to explicitly enables the script for all domains (// @include *).

I notice that the file you link to appears to contain three userscripts stuck together.
My guess is that you found that link in the GreaseMonkey/TamperMonkey section of the Installation table
on the main wikEd page.
My further suspicion is that (Grease|Tamper)Monkey have infrastructure to split multiple scripts into discrete files (though perhaps the link is just broken).
I don't believe that luakit has such infrastructure, and so the individual scripts may need to be installed separately.
(It looks like they're listed in a table on the installation page in the "Integrated into a wiki farm" section.)

It looks to me like maybe the script wikEd.js tests that the page is a wiki by looking for window.mw.
It also seems to include wikEdDiff.js.
wikEdDiff.js doesn't do any testing, and attempts to access a global mw variable.
My guess is that since you have wikEdDiff.js concatenated onto the end of wikEd.js, some safeguard breaks down,
and a variable that doesn't exist gets referenced, causing your error.
I haven't tested, so i can't confirm that the inclusion of wikEdDiff.js will work correctly in luakit.
It looks to me though, like it may be grabbed from Cacycle's user page, so you might only need to install the wikEd.js file.

@jindamvani
Copy link
Author

jindamvani commented May 17, 2023 via email

@taobert
Copy link
Contributor

taobert commented May 17, 2023

It seems, i cant install individual scripts.

Well you should be able to download the individual files, put them in your scripts directory, and rename wikEd.js as wikEd.user.js.
You should also be able to split the file you already downloaded with a text editor.
But maybe you don't need to, maybe all-the-scripts-together is how it should be.
Does it work as-is on sites that you'd expect it to work on?

reported upstream

Well, that's very efficient, but possibly premature -- it might not be their problem.
Though, i'd have expected a more restrictive @include range.
Perhaps the developer can rebut some of my assumptions above.

@jindamvani
Copy link
Author

jindamvani commented May 17, 2023 via email

@taobert
Copy link
Contributor

taobert commented May 18, 2023

wikEd.js [given under table heading: Source wiki page (integrated into a wiki farm)] given at
https://en.wikipedia.org/wiki/User:Cacycle/wikEd_installation#On-wiki_installation_code
is same as greasemonkey script given on same page.

In my hands, wikEd.js from the table (i've added "?action=raw" to strip off wikipedia's framing) is 19237 lines, and contains one userscript header:

tao@gozleme# wget -qO - 'https://en.wikipedia.org/wiki/User:Cacycle/wikEd.js?action=raw'|wc -l
19237
tao@gozleme# wget -qO - 'https://en.wikipedia.org/wiki/User:Cacycle/wikEd.js?action=raw'|grep ==UserScript==
// ==UserScript==

By contrast, the greasemonkey install link produces 25384 lines and three userscript headers:

tao@gozleme# wget -qO - 'https://en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Cacycle/wikEd.user.js'|wc -l
25384
tao@gozleme# wget -qO - 'https://en.wikipedia.org/w/index.php?action=raw&ctype=text/javascript&title=User:Cacycle/wikEd.user.js'|grep ==UserScript==
// ==UserScript==
// ==UserScript==
// ==UserScript==

It is working correctly.

Well then my failure to grasp what may well be a standard greasemonkey format may be a red herring,
and just adding more restrictive @includes might be the easiest solution for you.
I note though, that the installation page talks about enabling it as a wikipedia gadget,
which seems to remove the need to install anything.
If you weren't wanting to use the scripts for non-wikimedia sites, this might also work for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants