Discussions » Development

Standalone userscript server (proxy)

§
Posted: 2020/06/03

Standalone userscript server (proxy)

Hi there folks :)

I'm looking to deploy a greasemonkey script on the server side in a proxy. This is to make custom changes to a legacy monolithic compiled webapp so internal users can all benefit from the existing script without having to install the addon.

I found monkeygrease https://www.theserverside.com/discussions/thread/37475.html, from 2005 but it's website now seems to be a personal blog: http://www.monkeygrease.org/

Perl offers https://metacpan.org/pod/HTTP::Proxy::GreaseMonkey in CPAN, but it is also legacy (2007).

I considered if it would be possible to run a browser as a proxy, but have not found any documented way to do so.

I considered if it would be possible to run a userscript (greasemonkey, tampermonkey, violentmonkey, etc) as a standalone service, but I'm not sure how to approach this task.

Anyone have any ideas?

woxxomMod
§
Posted: 2020/06/03
Edited: 2020/06/03

Userscripts don't work with raw HTML responses, they need DOM and full JavaScript environment for the page and its DOM, they don't run on the server. This whole proxy thing most probably just adds a script tag that contains the userscript's code and a polyfill for GM_* functions. You can write the polyfill yourself and add the tags to the response using any [advanced] proxy software, I guess.

§
Posted: 2020/06/03

Sure, that's an approach that would work. We have a large library of userscripts that I'm trying to avoid rewriting though :(

woxxomMod
§
Posted: 2020/06/03

If your polyfill is good you won't need to rewrite the scripts. You can probably find existing GM polyfills (they're written in JavaScript just like userscripts). There'll be a problem with GM_xmlhttpRequest though: you'll probably have to set up an additional service on the proxy server so the gmxhr polyfill would use it to make cross-origin requests.

Post reply

Sign in to post a reply.