I want to write a chrome extension to upload my own browsing history to my database. But Baidu said that js can not connect to the database, do not know what the bosses have, please let me know!

js operates the database


there are feasible ways, but they all require that the database is your own, and is safe to feed the dog .

browser JavaScript cannot directly connect to the database, the most fundamental reason is that the host environment is the browser, and the browser generally does not provide TCP Socket directly to JavaScript, which is too dangerous. The closest Websocket is the application layer protocol, which the SQL server will not recognize at all. Is there any way to get TCP Socket? There is.

  1. Chrome Apps: is an enhanced version of Chrome Extension, originally designed for Chrome OS, then opened for other systems, and recently backed out, removing all Apps, from the store but API still hasn't deleted it. As a Native Apps substitute for Chrome OS, there is naturally a complete TCP Socket available. chrome.sockets.tcp can find out.
  2. Extension + Native: browsers do not give TCP Socket, but allow Extension to communicate with native programs, and native programs can open TCP Socket, at will. Building a local node server is actually very fast, and what you've learned before can be done in an hour (and you have to learn node sooner or later to write JavaScript, right?), which is faster than writing Chrome Apps. After all, you don't have to start from scratch with TCP. A lot of database packages on npm can be used.

but all of the above methods require that your database can be accessed directly from the public network. Considering the current domestic network environment, the subject should not have his own IP, then the database will be exposed to an entire network segment, and even think about it.

I would like to add that I thought it was amazing that JackDB, was mentioned in the comments of the above subject, so I signed up for it and found that it was just a shortcut to the website. That website also works in the way that third parties forward SQL requests. It's simple and rude for to give the password directly to the website .

clipboard.png


the front-end js certainly cannot directly manipulate the database, but you can send the data to the interface through ajax and write the data to the database through the interface.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b32be4-341ea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b32be4-341ea.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?