Page MenuHomePhabricator

Create browser extension to assist developing user scripts locally
Open, Needs TriagePublic

Description

Inspired by @Ed6767’s Develop Wikipedia Userscripts like a Pro, I think it would be useful to have a browser extension which, when enabled, automatically loads a script from a URL like http://localhost:8080/script.js. You would develop the user script locally, run http-server (or http.server or another server of your choosing) to serve it, and the extension would automatically load the code you’re working on, so that you don’t need to save anything on-wiki to make changes take effect.

Loose collection of envisioned features:

  • have an on-off switch in the browser toolbar, since people wouldn’t use this all the time; like WikimediaDebug
    • the on-off switch effectively replaces adding or removing mw.loader.load( 'http://localhost:8080/script.js' ); to your common.js
  • make the URL configurable to an extent (port and path, though I’m tempted to leave the localhost hard-coded)
  • avoid caching of the code, e.g. by automatically adding a random parameter to the URL (seems to work in http-server and http.server, at least)
  • work on all Wikimedia wikis (and the Beta cluster?)
  • be installable from the Firefox and Chrome extension stores
  • wait until the MediaWiki environment is available before loading the code (is typeof mw !== 'undefined' enough?)

Event Timeline

I’m not sure which tags to add to this task; for now I just wanted a place to hold this idea, and potentially discuss it with others.

I might work on this over the holidays :)

I'm glad my quick webcast inspired you to make this proposal - however, I think an entire browser extension would be overkill when, in my opinion, I think whilst slightly slower, a userscript or gadget could do a good job at this.

Also, in the video the caching issue was my fault. I typically use PHP for the HTTP server (with php -S) for larger projects like RedWarn, which doesn't have caching headers, so reading just works. I think by default http-server works differently.

How about this instead:
A VSCode extension and/or node.js script that starts a web server and also provides a websocket to inform the page when the script has been changed, and a corresponding user script that detects if the web server is online, connect to it and load the script, and automatically reload the page when the script is changed locally. Options could also be provided to switch skins on the Wiki being used to ensure compatibility (basically just redirect to ?useskin=example). The behaviour could be disabled by simply not running the web server.

Hm, to me it doesn’t feel like overkill – I don’t think a browser extension is that much extra work (at least for Firefox – I haven’t published a Chrome extension before, admittedly), and it has the potential to make users’ life easier.

Also, in the video the caching issue was my fault. I typically use PHP for the HTTP server (with php -S) for larger projects like RedWarn, which doesn't have caching headers, so reading just works. I think by default http-server works differently.

Ok, but surely we would still want this to work properly with http-server? :)

The behaviour could be disabled by simply not running the web server.

I’m not a big fan of this idea, both because of the (background) performance cost of constantly polling a nonexistent server, and also because I don’t like the idea of adding random code to the wiki if something else happens to run on that port (either due to something else accidentally using the same port number, or due to malware). That said, with the browser extension idea, you could get effectively this behavior by just leaving the switch enabled all the time. (I think the WikimediaDebug extension disables itself automatically after some time, but I’m not sure if I would copy that here.)

I've made this very basic yet functional tool as a proof of concept that it works as a user script: https://github.com/wikimedia-gadgets/EasyWikiDev

I made it where the user has to click the "develop" button to enable the check, and it uses websockets and VSCode's existing Run and Debug feature to start the server script.

Let me know what you think.