First of all, the extension of Chrome is not its plug-ins, many of the online say write plug-ins, in fact, are said to expand. Write extensions are not complicated, as long as there are a number of features that can be implemented based on a series of APIs provided by Chrome. There is a price to learn about the API, plus the domestic access to the Chrome website is not going well. Although 360 provides a translation document, and there are many examples, its content is still too little, some problems it still does not involve. So, there is no problem in doing a simple application, but the actual project development often does not have the useful introduction and explanation.
This series of articles will solve some practical problems, involving the following:
- Basic Configuration
- Content_script and Background_script
- Use of cookies
- Local storage
- Ajax requests Remote Data
Bo Master is also in the study, said is also the development process of some summary, not necessarily correct, if wrong, also please forgive.
Write extension only one file is fixed, others do not have any fixed requirements, such as fixed format, fixed folder and so on. This fixed file is its configuration file, a JSON-formatted file: Manifest.json, the basic content is as follows:
Manifest.json
{ "manifest_version": 2, "name": "My Extension", "description": "Extension description", "Version": "1.0"}
This is one of the simplest files and there are 2 issues to be aware of:
- Currently, manifest_version must be written as 2, so the rest of the numbers are not written, especially 1.
- In JSON, the last item is not available, the number is not, or it will be enabled to fail.
These items do not need to be introduced, you should know what they are, they will appear in the extension interface, the other is useless. A true extension is certainly not the only one. It can be involved, Bo Master simple summed up into two categories:
- Chrome browser elements, such as tab, bookmark, history, etc.
- Page content
So, if your extension needs to be involved, you have to add it to the configuration JSON, which is the Manifest.json file, if you need to use tab:
{ "manifest_version": 2, "name": "My Extension", "description": "Extension description", "Version": "1.0", "Permissions": ["Tabs" ]}
Permissions is allowed, it tells Chrome that the plugin is allowed to tab, or Chrome allows you to use its tab-related APIs. So, if you use bookmarks, or something else, you can write it in here. For example, we want to use agent-related APIs:
{ "manifest_version": 2, "name": "My Extension", "description": "Extension description", "Version": "1.0", "Permissions": ["Tabs", "proxy" ]}
Proxy means that you can use agent-related APIs, such as Cookie,history, and so on, with specific reference to the official documentation
The Chrome extension does not have strict requirements for the directory, so except for Manifest.json this file must be, the others are added on demand. The directory structure can be named according to your habits, no problem.
Get up and do the Chrome extension "Basic Introduction"