0

Concerning this flow logic from here Chrome Extension how to send data from content script to popup.html

  1. A content script is injected into each page matching some criteria.

  2. Once injected, the content scripts send a message to the event page (non-persistent background page) and the event page attaches a page=action to the tab.

  3. As soon as the page-action popup is loaded, it sends a message to the content script, asking for the info it needs.

  4. The content script processes the request, and responds so the page-action popup can display the info.

I suspect there will be a delay if the popup.js is triggered, because my ajax call is in content scripts. How to ensure there is no delay in using ajax in chrome extension?

Community
  • 1
  • 1
user3522749
  • 309
  • 3
  • 10
  • Network delay for the AJAX call will definitely dwarf any messaging delays, so what's the problem here? In any case, you can do XHRs from the popup itself. – Xan Sep 06 '14 at 09:38
  • @Xan I saw an extension is so smart of using ajax, it run at the background before the user even clicked on the popup.. why isn't that possible in my case? – user3522749 Sep 07 '14 at 15:01
  • It might be, but it's unclear what you're asking. – Xan Sep 07 '14 at 16:02
  • @Xan think of I want to load something using ajax before the user click on the popup.. how should the flow be? If I follow above approach, there will be a delay.. – user3522749 Sep 07 '14 at 16:13
  • There is nothing stopping your background page making ajax request on every page getting content scripts injected (or any other time). – abraham Sep 08 '14 at 01:19
  • @abraham so you are suggesting I do the ajax on background.js and send the callback to content script? – user3522749 Sep 08 '14 at 02:18
  • If you don't want users waiting for AJAX requests, you need to do them as soon as possible, as soon as the content script is injected into the page is that time. – abraham Sep 08 '14 at 02:44

0 Answers0