If you want your extension to interact with Web pages, you need a content script.
I have been paying attention to how to implement chrome extension and how chrome supports extension. I have seen helloworld in turorial before. I think it's so simple and what can I do. Today, I read the nkgestures source code and then re-read the chrome extension development documentation. I think the concept of content script is very important. Here I will record my understanding.
Chrome extensions are basically based on Java scripts (of course, you can call C/C ++ through other methodsCodeIn this way, Google is ready for browsers on different platforms in the future.
Chrome allows you to execute extended code when you open a window, tab, or other events. This code is called content scripts. Content scripts are JavaScript files that run in the context of web pages. by using the standard Document Object Model (DOM), they can read details of the web pages the browser visits, or make changes to them. at the same time, content scripts can communicate with extension through channel.
Content scripts can communicate with their parent extension using message passing. the content script opens a channel to the extension using the chrome. extension. connect () method and then sends messages back and forth to it. the messages can contain any valid JSON object (null, Boolean, number, String, array, or object ).
The parent extension can also open a channel to a content script in a given Tab by callingchrome. Tabs. Connect (Tabid ).
When a channel is opened from a content script to an extension, the onconnect event is fired in all views in the extension. any view can receive the event. the event contains a port object, which can be used by the extension view to communicate back to the content scrip