Userscripts vs. Chrome Extension

Avi Meir picture Avi Meir · Nov 21, 2012 · Viewed 10.3k times · Source

I am developing an extension that will read HTML elements value, then make API calls to an external website, get the results and display them in newly created HTML elements.

What are the pro/cons of writing it in native chrome extensions vs. userscripts?

Answer

Rob W picture Rob W · Nov 21, 2012

There are a few differences between a native Chrome extension and a user script.

See this wiki section for a list of differences between Greasemonkey scripts and Chrome userscripts.

If you want to take advantage of cross-browser user scripts, try to not use GM_* methods or unsafeWindow.

From a developer's perspective, there is no advantage of preferring either User scripts or Chrome extensions, because any user script can easily be embedded in a Chrome extension.

If you view this topic in the light of deployment, then the differences are significant:

  • One-click install is only available in the Chrome Web Store. Native extensions only.
  • Both user scripts and native extensions can be dragged from the local file browser to the Extensions page to install the extension.
    (User scripts are converted to Chrome extensions; warning: see below)
  • Native user script support will stop working at the end of 2013, because converted user scripts use manifest version 1, which has been deprecated.

Conclusion

I recommend to develop native extensions. You can easily create a Chrome extension from a user script by using the following directory structure:

manifest.json
whatever.user.js

Minimal manifest.json:

{
     "name": "name of extension",
     "version": "1",
     "manifest_version": 2,
     "content_scripts": [{
         "js": ["whatever.user.js"],
         "matches": ["http://example.com/*"]
      }]
}

See also