Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to communicate between content script and the panel

How does the communication between a panel and a content script happen? How can we dynamically update the panel content from content script? The content script accesses the DOM of the page loaded. Now every time when there is a DOM change in the webpage that should be shown in the panel. How can we do this? Can anyone explain with an example?

UPDATE: here is MY ADDON CODE

Please go through this code. I am not getting the output

like image 408
user1275375 Avatar asked May 22 '12 04:05

user1275375


People also ask

How do I send a message from content script to popup?

If you are sending messages from content script to popup, then you just need to use chrome. runtime. sendMessage instead of tabs. sendMessage .

What is the difference between content script and background script?

Background Script - Provides persistence and handles background events. Content Script - Scripts that run in isolation in the context of the web page. Injected Script - Scripts that are programmatically injected into the web page.

What is content scripting?

A content script is a part of your extension that runs in the context of a particular web page (as opposed to background scripts which are part of the extension, or scripts which are part of the website itself, such as those loaded using the <script> element).


1 Answers

Your question is about communication between two content scripts - one content script loaded into a web page and another content script loaded into the panel. These content scripts cannot communicate directly, they have to communicate through the extension (main.js or whatever module created them). In other words: a change in the web page happens, the content script recognizes that change and sends a message to the extension. The extension receives the message and sends it to the content script in the panel. The content script in the panel then updates panel contents as necessary.

like image 155
Wladimir Palant Avatar answered Oct 26 '22 18:10

Wladimir Palant