1

I'm working on my first chrome extension. My extension works on specific pages. I need to access the current page of the user, and get values from the 'table' element in the page.

Do I need contentscript page or is background.html enough? How do I access the table element then?

Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
Nikhil
  • 6,493
  • 10
  • 31
  • 68

1 Answers1

1

Read this SO question in order to understand the difference between content script and background script. Now, back to your question

Since you want to get access to the DOM element of the current page, you need to do the following:-

  1. In your manifest.json, make sure you have the url pattern which matches the current page url.

  2. Make your your content script runs after page load on the current page

  3. Once you ensure 1 and 2, you can use simple query selectors to get access to the table element and get the values you need.

Now it depends what you do want to do with the table values you have obtained. If you need them in the background script for storage purpose or some other purpose, you can use Mesage Passing to send the values to background script.

Community
  • 1
  • 1
Sachin Jain
  • 21,353
  • 33
  • 103
  • 168
  • Thanks for ur time. How can make my content script to run after the page starts? By the way,just installed ur 'stackeye'.I'm loving it, very useful tool.:) – Nikhil Mar 17 '14 at 07:21
  • @nikhil in your manifest.json you can specify `run_at` field and set it to `document_end`. Look at https://developer.chrome.com/extensions/content_scripts and search for run_at and read the context. Hope it helps!! – Sachin Jain Mar 17 '14 at 07:59
  • Thanks for appreciation about StackEye..I would love it if you can post a review on chrome store or even rate it there :) – Sachin Jain Mar 17 '14 at 08:00
  • blundeboy, I progressed further on my extension, but got stuck All I want to do is send value of variable from contentscript to popup.js and its not working.Can u help me out with this?http://stackoverflow.com/questions/22501531/how-to-resolve-undefined-and-nan – Nikhil Mar 22 '14 at 04:05