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?
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:
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/*"]
}]
}
The case for writing (and sharing!) user scripts: as long as you just use normal browser DOM APIs, your script can with minimal effort be picked up and made to run (often just installing it without edits) by anyone using another user script capable browser.
The case against them, when you use Google Chrome, is that as of Chrome 21, installing them got ridiculously messy: you need to right click the installation link, save it to disk, open the extensions page, and drag the saved script in there (yes), or install TamperMonkey from the Chrome Web Store (it is free, and does for Chrome essentially what Greasemonkey does for Firefox: gives user script installation and maintenance a bearable user interface).
While you only need to do the things you list, you may not need any more privileged API access than what user scripting gives you natively: try executing the XMLHttpRequest code you would be writing for the script in the devtools console when on another site and you'll see if it's enough for your needs or not. Many web APIs these days allow CORS support, which might save your use case from needing to resort to the proprietary browser-native extension APIs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With