5 votes

Converting Userscript to Chrome Extension: The monkeys are no longer needed

5 comments

  1. [3]
    inwardpath
    Link
    Doesn't this only make sense if you use very few scripts? I'm not going to take 20 scripts and 1 extension and turn that into installing 20 separate extensions...

    Doesn't this only make sense if you use very few scripts? I'm not going to take 20 scripts and 1 extension and turn that into installing 20 separate extensions...

    5 votes
    1. [2]
      noble_pleb
      Link Parent
      I've just migrated my first script to an extension, so I don't know much about extension development yet! But I'm sure there must be ways of clubbing multiple scripts into one. I'd start with...

      I've just migrated my first script to an extension, so I don't know much about extension development yet! But I'm sure there must be ways of clubbing multiple scripts into one. I'd start with clubbing a few entries into the manifest.json -> "content_scripts" section and test that. The scripting extensions like greasemonkey, etc. must be doing the same internally.

      Turning the scripts to extension will also help you get started with learning extension development which could be helpful later as they're much powerful components (in terms of functionality) compared to userscripts.

      1 vote
      1. inwardpath
        Link Parent
        Gotcha, sounds like there are ways to combine multiple. That said, I don't use Chrome or Chromium browsers, nor am I really interested in extension development myself, at least for the time being,...

        Gotcha, sounds like there are ways to combine multiple. That said, I don't use Chrome or Chromium browsers, nor am I really interested in extension development myself, at least for the time being, so this isn't for me- I was coming at it more from a user perspective than a dev perspective in my original post. The info in your reply is helpful though (especially to others, I'm sure!)

        Now that I'm looking at it from a dev perspective though, it's something to keep in mind, at least, if I ever have some userscript idea that I'd like to flesh out into a full extension.

        1 vote
  2. [2]
    Wes
    Link
    Ah, I was expecting this to be about MV3 and the scripting API. I think converting your own scripts to extensions can make sense, but you do lose a few features. TamperMonkey offers very quick...

    Ah, I was expecting this to be about MV3 and the scripting API.

    I think converting your own scripts to extensions can make sense, but you do lose a few features. TamperMonkey offers very quick debugging/editing features, and syncing of scripts through a cloud service (which also acts as a backup). Unless you upload your extensions to the Chrome Store I don't believe you'd get the advantage of syncing between computers.

    I'd be curious to measure the performance differences. Memory-wise, I figure there's a small amount of overhead from the GreaseMonkey extension itself, but there's probably more overhead from running numerous extensions in place of one. Each is sandboxed and runs in its own process which isn't free.

    Speed-wise, "true" extensions may get the benefit of deeper optimizations. Better JIT, memoization? I don't really know. I expect it would be pretty minor unless you move to MV3 service workers (over background pages).

    3 votes
    1. noble_pleb
      Link Parent
      Actually, I'm quite new to JS extension development, this was my first userscript->extension conversion! Regarding your concern of running numerous extensions, that doesn't seem to be the case....

      Actually, I'm quite new to JS extension development, this was my first userscript->extension conversion! Regarding your concern of running numerous extensions, that doesn't seem to be the case. Based on this StackOverflow post, it looks like you can inject more than one script in the manifest.json configuration of a single extension, and also control in what order they execute and when ("run_at": "document_start", for example). I'm going to try this soon to convert multiple userscripts to extension!

      2 votes