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

Improvements for GreaseMonkey support #3238

Open
6 of 28 tasks
The-Compiler opened this issue Nov 3, 2017 · 20 comments
Open
6 of 28 tasks

Improvements for GreaseMonkey support #3238

The-Compiler opened this issue Nov 3, 2017 · 20 comments
Labels
priority: 2 - low Issues which are currently not very important.

Comments

@The-Compiler
Copy link
Member

The-Compiler commented Nov 3, 2017

Things which could be improved after #3040 is in:

cc @toofar

@The-Compiler The-Compiler added the priority: 2 - low Issues which are currently not very important. label Nov 3, 2017
@jgkamat
Copy link
Member

jgkamat commented Nov 3, 2017

If anyone is thinking about using webchannels, I have a branch you can steal from where I started to work on this (to support follow_selected a while back) but I trashed it because it was not needed.

@toofar
Copy link
Member

toofar commented Dec 23, 2017

Also support regular expressions in @include and friends, we are currently only supporting globbing via fnmatch. zro in irc pointed out a good example script https://github.com/StylishThemes/GitHub-Dark-Script

@The-Compiler
Copy link
Member Author

The-Compiler commented Jan 17, 2018

Known broken scripts:

@The-Compiler
Copy link
Member Author

OneeChan (and anything else defining global variables which collide with the page or other scripts) now works properly since #3793 - thanks @toofar!

@rnhmjoj
Copy link
Contributor

rnhmjoj commented Sep 23, 2018

I have found an issue with a script I made:

// ==UserScript==
// @name         Kill subreddit style
// @description  Unload all subreddits custom stylesheets
// @author       rnhmjoj
// @include      https://old.reddit.com/r/*
// @version      1.0.0
// @run-at       document-start
// @grant        none
// ==/UserScript==

for(var link of document.getElementsByTagName("link")) {
  if(link.title == "applied_subreddit_stylesheet")
    link.disabled = true;
}

The script doesn't work because document.getElementsByTagName("link") returns an empty array when running from greasemonkey, pasting the code into the console however works fine.

@toofar
Copy link
Member

toofar commented Sep 23, 2018

That's just because it is running too early before those elements have been added. Try changing the // @run-at document-start to // @run-at document-end. (document-idle is even later but doesn't appear to be necessary here.)

@rnhmjoj
Copy link
Contributor

rnhmjoj commented Sep 23, 2018

Ah, thank you! it's working. This used to work with violentmonkey... is it just slower to load the scripts then?

@toofar
Copy link
Member

toofar commented Sep 23, 2018

Oh that's interesting, and annoying. QtWebEngine handles the events for us so maybe that gets access to earlier triggers than extensions do.

@The-Compiler
Copy link
Member Author

The-Compiler commented Sep 24, 2018

The Greasemonkey wiki says that only document-end works in Greasemonkey 4.x (the WebExtensions port) - maybe something similar is true for Violentmonkey as well.

FWIW the document.readyState docs say "We can now access the DOM elements." for the interactive state, which implies we can't for the loading state, which document-start corresponds to.

In other words, I think this is fine, and your script should use document-end 😉

edit: Oh, just found the Violentmonkey docs which say:

Note: in Greasemonkey v3, the script may be ensured to execute even before HTML is loaded, but this is impossible for Violentmonkey as a web extension.

@slashome
Copy link

Don't know if I should be this here , but I made a script for Trello's plugin that add cost to task that display the total cost for a list. It works fine on Chrome but it seems to have a conflict with newrelic.js in qutebroser :

Uncaught TypeError: Illegal invocation
    at Proxy.s (newrelic.js:664)
    at userscript:GM-Trello Cost Counter:245
    at userscript:GM-Trello Cost Counter:248
    at userscript:GM-Trello Cost Counter:253

The rewrelic.js line :

            try {
              return s = t.apply(a, r)
            } catch (d) {
              throw u(e + "err", [r, a, d], c), d         <----
            } finally {
              u(e + "end", [r, a, s], c)
            }

My script link is :
https://github.com/slashome/userscripts

Don't know if there is anything I can try to fix it :/

Thx again for this awesome browser !

@toofar
Copy link
Member

toofar commented Oct 29, 2018 via email

@user202729
Copy link
Contributor

  • @match https://stuff.com/* also matches view-source:https://stuff.com/.
  • Perhaps the script name should be edited so clicking the script name (in console.log messages in the inspector tools for example) opens it? When there are spaces or - in the name it doesn't work. (This might be a chromium bug fixed in some recent version. I'm not sure)

@amacfie
Copy link
Contributor

amacfie commented Oct 2, 2020

Does GM_openInTab currently require content.javascript.can_open_tabs_automatically = True?

@The-Compiler
Copy link
Member Author

@amacfie I think so - why are you asking?

@LiteracyFanatic
Copy link
Contributor

It would be nice if there was a setting to enable/disable the loading of GreaseMonkey scripts. Sometimes I will encounter odd behavior on a page which I suspect may be related to one of my scripts and would like to quickly check if the page functions correctly without them. Right now I append .disabled to the end of each script and then run :greasemonkey-reload and reload as a workaround.

@The-Compiler
Copy link
Member Author

Similarly to what @LiteracyFanatic already mentioned, I think it'd be great to have :greasemonkey-{dis,en}able commands which either disable/enable all scripts, or the script given to it (with completion of currently disabled/enabled scripts).

@Ninlives
Copy link

Any good news for cross-origin GM_xmlhttpRequest?

@toofar
Copy link
Member

toofar commented Feb 16, 2022

@Ninlives no good news sorry. None on the horizon either.
I think it came up last year but I don't even remember how the discussion went. "It" being how we could or couldn't provide a privileged (compared to the normal JS APIs) bridge between python and javascript that we were comfortable inflicting on all of the qutebrowser users. The risk being that javascript coming from places other than greasemonkey scripts could make use of the same channel. It looks like a tough problem still and we have plenty of other things that require more urgent attention.

@cortsf
Copy link

cortsf commented May 28, 2024

Just leaving this comment to upvote implementing GM_getResourceText. It was mentioned that nobody else asked for it on #3975 so I'm just raising one more hand.

Do you think there is any workaround in the meantime? For example, reading a local file in config.py, and setting a variable which could be read from the greasemonkey script?

Thanks

@The-Compiler
Copy link
Member Author

The obvious workaround is to include your resource in your JS file. Other than that, no. There's no way for Greasemonkey to access Python stuff, see the comment just above yours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: 2 - low Issues which are currently not very important.
Projects
None yet
Development

No branches or pull requests

10 participants