I want to build a browser extension that can read/write from the database that is behind my web app.
However, I don't really understand how that would work conceptually and what the best practices are? Should/can the extension communicate directly with the database? Is there some layer in between that I'm missing?
-
2This is really broad... A good answer could fill an entire book. Can you make your question more specific?Robert Harvey– Robert Harvey2018年07月16日 18:06:41 +00:00Commented Jul 16, 2018 at 18:06
-
Hi @RobertHarvey! The reason it's so broad is because I don't really know much about the topic to make it any more specific. I can try my best though.Dynamic– Dynamic2018年07月16日 18:07:56 +00:00Commented Jul 16, 2018 at 18:07
-
Start here: developer.mozilla.org/en-US/Add-ons/WebExtensions/…Robert Harvey– Robert Harvey2018年07月16日 18:14:12 +00:00Commented Jul 16, 2018 at 18:14
1 Answer 1
A browser extension (web extension) is basically a web app where all the JS and other resources are already loaded in the browser. The functional difference to an ordinary website is that a web extension has has more privileges and has access to more browser APIs.
You use the same basic techniques to build web extensions that you'd use to build a (single page) web application. The web extension will communicate through normal HTTP requests with external services. If you want to access a database, the best practice is to build a backend server that exposes an API (usually in RESTful style). If you already have a web app, the web extension can likely reuse the same backend of the web app.
Note that thanks to advancements under the umbrella term "progressive web apps", many features that would previously have required a privileged extension are also available to ordinary web apps, e.g. notifications, background processes, or persistent offline storage.