Hacker News new | ask | show | jobs
by insin 2250 days ago
> We could create a browser extension, but that means developing one for all major browsers.

Personally, I use most of the extensions I've written in userscript form via Greasemonkey for the convenience of being able to drop straight into editing and testing it when I spot something which could be added or needs to be fixed.

If your userscript doesn't depend on any APIs provided by the userscript manager you're using, you can package it up as a WebExtension by adding a manifest.json:

    {
      "manifest_version": 2,
      "name": "Your Userscript",
      "version": "1.0",
      "content_scripts": [
        {
          "matches": [
            "https://example.com/*",
          ],
          "js": [
            "./your-userscript.user.js"
          ]
        }
      ]
    }
Once you've dropped a manifest.json in, web-ext [1] is handy for running extensions in Firefox and Chrome in a temporary profile/developer mode. It also reloads the extension when you make changes.

This is particularly useful if your script grows to the point where it could benefit from an options screen, as you can configure `"options_ui": {"page": "options.html"}` instead of having to hack an options UI into the target site yourself.

[1] https://github.com/mozilla/web-ext

1 comments

I thought web-ext was only for Firefox, and I didn't see anything in the Readme about Chrome?
Looks like it's only in the release notes [1] - I only spotted it recently myself while updating an extension, it's:

    web-ext run --target chromium
[1] https://github.com/mozilla/web-ext/releases
Thank you!