Important Concepts in chrome Extension: Content scripts

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.